Problem: While exploring the old caves, researchers found a book, or more precisely, a stash of mixed pages from a book. Luckily, all of the original pages are present and each page contains its number. Therefore, the researchers can reconstruct the book.

After taking a deeper look into the contents of these pages, linguists think that this may be some kind of dictionary. What's interesting is that this ancient civilization used an alphabet which is a subset of the English alphabet, however, the order of these letters in the alphabet is not like the one in the English language.

Given the contents of pages that researchers have found, your task is to reconstruct the alphabet of this ancient civilization using the provided pages from the dictionary.

Input

First-line contains two integers: n and k (1 ≤ n, k ≤ 10^3) — the number of pages that scientists have found and the number of words present at each page. Following n groups contain a line with a single integer p_i (0 ≤ n < 10^3) — the number of i-th page, as well as k lines, each line containing one of the strings (up to 100 characters) written on the page numbered p_i.

Output

Output a string representing the reconstructed alphabet of this ancient civilization. If the book found is not a dictionary, output "IMPOSSIBLE" without quotes. In case there are multiple solutions, output any of them.

Example

Input


3 3
2
b
b
bbac
0
a
aca
acba
1
ab
c
ccb


Output


acb

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class Main implements Runnable {
    static int mod = 1000_000_007;
    static long lim = (long)1e9 + 6;
    static long mod1 = 998244353;
    static boolean fileIO = false;
    static FastScanner f;
    static int inf = 2000_000_000;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static long iinf = Long.MAX_VALUE;
    static double eps = (double)1e-6;
    static HashSet<Character> h;
    static StringBuffer ans;
    static StringBuffer ord;
    static class Graph { 
        private final LinkedList<Integer>[] adj;   
        Graph(int n) { 
            adj = new LinkedList[n]; 
            for (int idx = 0; idx < n; ++idx) { 
                adj[idx] = new LinkedList<>(); 
            } 
        } 

        void addEdge(int src, int tar) { 
            adj[src].add(tar); 
        } 
  
        // Top sort
        private void topS(int curr, boolean[] vis, Stack<Integer> st) { 
            vis[curr] = true; 
            for (int v : adj[curr]) { 
                if (!vis[v]) { 
                    topS(v , vis , st); 
                } 
            } 
            st.push(curr); 
        } 

        void Sort() { 
            Stack<Integer> st = new Stack<>(); 
            boolean[] vis = new boolean[adj.length]; 
            for (int i = 0; i < adj.length; i++) { 
                vis[i] = false; 
            } 

            for (int i = 0; i < adj.length; i++) { 
                if (!vis[i]) { 
                    topS(i, vis, st); 
                } 
            } 
            while (st.size() > 0) { 
                char c = (char)('a' + st.pop());
                if (h.contains(c)) ans.append(c);
                ord.append(c);
            } 
        } 
    } 
    public static void solve() {
        int n = f.ni(); int k = f.ni();
        String dict[] = new String[n * k];
        ans = new StringBuffer("");
        ord = new StringBuffer("");
        int ptr = 0;
        h = new HashSet<>();
        for (int i = 0; i < n; ++i) {
            int pgnum = f.ni();
            ptr = pgnum * k;
            for (int j = 0; j < k; ++j) {
                dict[ptr] = f.next();
                for (char c : dict[ptr].toCharArray()) h.add(c);
                ++ptr;
            }
        }

        Graph g = new Graph(26); 
        for (int i = 0; i < dict.length - 1; i++) { 
            String w1 = dict[i]; 
            String w2 = dict[i + 1]; 
            for (int j = 0; j < Math.min(w1.length(), w2.length()); ++j) {
                if (w1.charAt(j) != w2.charAt(j)) { 
                    g.addEdge(w1.charAt(j) - 'a', w2.charAt(j)- 'a'); 
                    break; 
                } 
            } 
        }

        g.Sort(); 
        boolean ok = true;
        int idx[] = new int[26];
        for (int i = 0; i < ord.length(); ++i) idx[ord.charAt(i) - 'a'] = i;

        search: for (int i = 0; i < dict.length - 1; ++i) {
            String w1 = dict[i];
            String w2 = dict[i + 1];

            for (int u = 0; u < Math.min(w1.length(), w2.length()); ++u) {
                if (w1.charAt(u) != w2.charAt(u)) {
                    if (idx[w1.charAt(u) - 'a'] > idx[w2.charAt(u) - 'a']) {
                        ok = false;
                        break;
                    }
                    continue search;
                }
            }
            if (w1.length() > w2.length()) ok = false;
        }
        
        if (!ok) pn("IMPOSSIBLE");
        else pn(ans);
    }    
    public static void main(String[] args)throws IOException {
        new Thread(null , new Main() , "F*uckit" , 1 << 28).start();  
    }
        
/******************************END OF MAIN PROGRAM*******************************************/
    public void run() {
        f = new FastScanner(System.in);
        //pre();
        int t = 1;
        int tt = 1;
        //fw = new FileWriter("!out.txt");
        while(t --> 0) {
            //fw.write("Case #" + (tt++) + ": ");
            //fw.write("\n");
            solve();
        }
        pw.flush(); 
        pw.close();
        //fw.close();  
    }
    public static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastScanner.SpaceCharFilter filter;
 
        public FastScanner(InputStream stream) {
            this.stream = stream;
        }
 
        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
 
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
 
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }
 
        public int ni() {
            int c = read();
 
            while (isSpaceChar(c))
                c = read();
 
            int sgn = 1;
 
            if (c == '-') {
                sgn = -1;
                c = read();
            }
 
            int res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
 
            return res * sgn;
        }
 
        public long nl() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
 
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }
 
        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));
            return res.toString();
        }
 
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
 
        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void pn(Object o){pw.println(o);}
    public static void pi(Object o){pw.print(o);pw.flush();}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0l)return a;else{return gcd(b,a%b);}}
    static long lcm(long a,long b){return (a*b/gcd(a,b));}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b, long m){long res=1;while(b>0){if((b&1)==1)res=((res%m)*(a%m))%m;b>>=1;a=((a%m)*(a%m))%m;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n+1];for(int i=1;i<=n;++i){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n+1];for(int i=1;i<=n;++i){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);} // Credits - KharYusuf for Multiset Class
    static class MultiSet<T extends Comparable<T>>{public int size=0;public TreeMap<T,Integer> tr;public MultiSet(){tr=new TreeMap<>();}public void add(T u){tr.put(u,tr.getOrDefault(u,0)+1);++size;}public boolean contains(T u){return tr.containsKey(u);}public void clear(){tr.clear();}}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}