// Arup Guha
// 10/13/2026
// Solution to Kattis Problem: Easy as CAB
// Illustrates Topological Sort
// https://open.kattis.com/problems/easyascab

import java.util.*;

public class easyascab {

	public static void main(String[] args) {
	
		// Get basic input.
		Scanner stdin = new Scanner(System.in);
		int n = stdin.next().charAt(0)-'a'+1;
		int numW = stdin.nextInt();
		
		// Set up graph.
		ArrayList<Integer>[] graph = new ArrayList[n];
		for (int i=0; i<n; i++) {
			graph[i] = new ArrayList<Integer>();
		}
		int[] indegrees = new int[n];
		
		// Read all of the words.
		char[][] words = new char[numW][];
		for (int i=0; i<numW; i++)
			words[i] = stdin.next().toCharArray();
		
		boolean possible = true;
		
		// Loop through consecutive pairs.
		for (int i=0; i<numW-1; i++) {
		
			int idx = firstDiff(words[i], words[i+1]);
			
			// Impossible case.
			if (idx == words[i+1].length && words[i].length > idx) {
				possible = false;
				break;
			}
			
			// No new knowledge.
			if (idx == words[i].length) continue;
			
			// Add edge, update indegree...
			int u = words[i][idx] - 'a';
			int v = words[i+1][idx] - 'a';
			graph[u].add(v);
			indegrees[v]++;
		}
		
		// Get this out of the way.
		if (!possible) {
			System.out.println("IMPOSSIBLE");
			return;
		}
		
		// Ta da!
		System.out.println(topSort(graph, indegrees));
	}
	
	// Returns the string as specified by the problem.
	public static String topSort(ArrayList<Integer>[] graph, int[] indegrees) {
		
		boolean queueTwo = false;
		LinkedList<Integer> queue = new LinkedList<Integer>();
		
		// Add anything that doesn't have an edge coming into it.
		for (int i=0; i<graph.length; i++)
			if (indegrees[i] == 0)
				queue.offer(i);
			
		// Store the top sort here.
		char[] res = new char[graph.length];
		int curIdx = 0;
		
		// Run top sort.
		while (queue.size() > 0) {
			
			// Mark this.
			if (queue.size() > 1) queueTwo = true;
			
			// Next item.
			int cur = queue.poll();
			res[curIdx++] = (char)(cur+'a');
			
			// Update all indegrees.
			for (Integer next: graph[cur]) {
				indegrees[next]--;
				if (indegrees[next] == 0) 
					queue.offer(next);
			}
		}
		
		// Impossible case.
		if (curIdx < graph.length) return "IMPOSSIBLE";
		
		// There was more than 1 way that would have worked.
		if (queueTwo) return "AMBIGUOUS";
		
		// Here's the one valid order.
		return new String(res);
	}
	
	// Returns the first index that the two strings are different, or the length
	// of the shorter string if one is a prefix of the other.
	public static int firstDiff(char[] prev, char[] next) {
	
		// Find the first different and return.
		for (int i=0; i<prev.length && i <next.length; i++)
			if (prev[i] != next[i])
				return i;
				
		// Return shorter length.
		return Math.min(prev.length, next.length);
	}

}