// Arup Guha
// 11/5/2016 (written late at night after contest) - edited my Dueling Philosopher's Solution...
// Solution to SER 2016 Division II Problem C: As Easy As C-A-B

import java.util.*;

public class cab {

	public static int n;
	public static vertex[] graph;

	public static void main(String[] args) {

		// Set up graph.
		Scanner stdin = new Scanner(System.in);
		n = stdin.next().charAt(0) - 'a' + 1;
		graph = new vertex[n];
		for (int i=0; i<n; i++)
			graph[i] = new vertex();

		boolean prefixProblem = false;

		int numW = stdin.nextInt();
		String w1 = stdin.next();
		
		// Go through each word in order.
		for (int i=1; i<numW; i++) {

			// Get next word.
			String w2 = stdin.next();

			int x=0,y=0;
			
			// Find the "difference" between these adjacent words.
			while (x<w1.length() && y<w2.length()) {
				if (w1.charAt(x) != w2.charAt(y))
					break;
				x++;
				y++;
			}

			// Add the appropriate edges.
			if (x<w1.length() && y<w2.length()) {
				graph[w1.charAt(x)-'a'].out.add(w2.charAt(y)-'a');
				graph[w2.charAt(y)-'a'].in.add(w1.charAt(x)-'a');
			}
			
			// Tricky prefix case!
			else if (w1.length()>w2.length())
				prefixProblem = true;

			// Get ready for next iteration.
			w1 = w2;
		}

		if (prefixProblem)
			System.out.println("1");
		else {

			// Set up graph and run the top sort and output its result
			topSort ts = new topSort(graph);
			System.out.println(ts.runAlg());
		}
	}
}

// Allows us to quickly add and subtract vertices from a graph...
class vertex {

	public HashSet<Integer> in;
	public HashSet<Integer> out;

	public vertex() {
		in = new HashSet<Integer>();
		out = new HashSet<Integer>();
	}
}

class topSort {

	// Easier to run our sort storing all this stuff in an object.
	private int[] ordering;
	private boolean[] used;
	private int n;
	private vertex[] eList;

	// Set everything up to start the algorithm.
	public topSort(vertex[] list) {
		eList = list;
		n = list.length;
		used = new boolean[n];
		ordering = new int[n];
	}

	// Here is our topological sort, adjusted to return 0, 1 or 2, for
	// 0, 1 or more than 1 possible sorted output.
	public String runAlg() {

		// Fill spots forward.
		int curIndex = 0;
		int retVal = 1;
		while (curIndex < n) {

			// Pre-count vertices in this step.
			int cnt = 0;
			int[] remove = new int[n];
			for (int i=0; i<n; i++)
				if (!used[i] && eList[i].in.size() == 0)
					remove[cnt++] = i;

			// If no vertices have in degree 0 at any iteration, algorithm fails.
			if (cnt == 0) return "1";

			// Stores that if we find 1 viable option later, there must at least be 2.
			if (cnt > 1) retVal = 0;

			// Now process 0 degree vertices, deleting them.
			for (int i=0; i<cnt; i++) {

				// Put this item in our list.
				ordering[curIndex] = remove[i];
				curIndex++;
				used[remove[i]] = true;

				// Remove edges leaving i.
				for (Integer e: eList[remove[i]].out)
					eList[e].in.remove(remove[i]);
			}
		}

		if (retVal == 0) return "0";
		String res = "";
		for (int i=0; i<n; i++)
			res = res + (char)(ordering[i]+'a');
		return res;
	}

}