It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in the fest which claims to evolve any Pokemon. The type of a Pokemon could change after evolving, subject to the constraint that if two Pokemon have the same type before evolving, they will have the same type after evolving. Also, if two Pokemon have different types before evolving, they will have different types after evolving. It is also possible that a Pokemon has the same type before and after evolving. 

Formally, an evolution plan is a permutation f of {1, 2, ..., m}, such that f(x) = y means that a Pokemon of type x evolves into a Pokemon of type y.

The gym leaders are intrigued by the special evolution camp and all of them plan to evolve their Pokemons. The protocol of the mountain states that in each gym, for every type of Pokemon, the number of Pokemon of that type before evolving any Pokemon should be equal the number of Pokemon of that type after evolving all the Pokemons according to the evolution plan. They now want to find out how many distinct evolution plans exist which satisfy the protocol.

Two evolution plans f1 and f2 are distinct, if they have at least one Pokemon type evolving into a different Pokemon type in the two plans, i. e. there exists an i such that f1(i) ≠ f2(i).

Your task is to find how many distinct evolution plans are possible such that if all Pokemon in all the gyms are evolved, the number of Pokemon of each type in each of the gyms remains the same. As the answer can be large, output it modulo 109 + 7.

Input

The first line contains two integers n and m (1 ≤ n ≤ 105, 1 ≤ m ≤ 106) — the number of gyms and the number of Pokemon types.

The next n lines contain the description of Pokemons in the gyms. The i-th of these lines begins with the integer gi (1 ≤ gi ≤ 105) — the number of Pokemon in the i-th gym. After that gi integers follow, denoting types of the Pokemons in the i-th gym. Each of these integers is between 1 and m.

The total number of Pokemons (the sum of all gi) does not exceed 5·105.

Output

Output the number of valid evolution plans modulo 109 + 7.

Examples

Input

2 3
2 1 2
2 2 3


Output

1


Input

1 3
3 1 2 3


Output

6


Input

2 4
2 1 2
3 2 3 4


Output

2


Input

2 2
3 2 2 1
2 1 2


Output

1


Input

3 7
2 1 2
2 3 4
3 5 6 7


Output

24

Note

In the first case, the only possible evolution plan is: 

<image>

In the second case, any permutation of (1, 2, 3) is valid.

In the third case, there are two possible plans: 

<image> <image>

In the fourth case, the only possible evolution plan is: 

<image>
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
        ConsoleIO io = new ConsoleIO(new InputStreamReader(System.in), new PrintWriter(System.out));
        //ConsoleIO io = new ConsoleIO(new FileReader("D:\\fbhc\\fighting_the_zombie.txt"), new PrintWriter(new File("D:\\fbhc\\out.txt")));
        new Main(io).solve();
        io.close();
    }
    ConsoleIO io;
    Main(ConsoleIO io) {
        this.io = io;
    }

    long MOD = 1_000_000_007;
    int N, M, W, K, Q;

    public void solve() {
        int n = io.ri();
        int m = io.ri();

        HashMap<Integer, List<Integer>> all = new HashMap<>();
        //int[] proc = new int[m];
        for(int i = 0;i<n;i++){
            int g = io.ri();

            for(int j = 0;j<g;j++){
                int v = io.ri()-1;
                //if(proc[v]<=i){
                //    proc[v]=i+1;
                    if(!all.containsKey(v))all.put(v, new ArrayList<>());
                    all.get(v).add(i);
                //}
            }
        }
        int other = m - all.size();
        long res = 1;
        for(int i = 1;i<=other;i++){
            res = (res*i)%MOD;
        }
        Queue<Bucket> queue = new LinkedList<>();
        queue.add(new Bucket(0, new ArrayList<>(all.values())));
        int[] cur = new int[n];
        List<List<Integer>> aaa = new ArrayList<>();
        for(int i = 0;i<n;i++)aaa.add(new ArrayList<>());
        int iter = 0;
        while(queue.size()>0) {
            Bucket bucket = queue.remove();
            List<List<Integer>> list = bucket.list;
            int k = bucket.k;
            long x = 1;
            long y = 1;
            List<Integer> toAdd = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                List<Integer> nums = list.get(i);
                if (nums.size() <= k) {
                    y  = (y*x)%MOD;
                    x++;
                } else {
                    int v = nums.get(k);
                    if(cur[v] <= iter){
                        cur[v] = iter+1;
                        aaa.set(v, new ArrayList<>());
                        toAdd.add(v);
                    }
                    aaa.get(v).add(i);
                }
            }
            for(int i = 0;i<toAdd.size();i++) {
                int v = toAdd.get(i);
                List<Integer> pp = aaa.get(v);
                if (pp.size() > 1) {
                    List<List<Integer>> next = new ArrayList<>();
                    for (int j = 0; j < pp.size(); j++) next.add(list.get(pp.get(j)));
                    queue.add(new Bucket(k + 1, next));
                }
            }
            if (x > 1)
                res = (res * y) % MOD;
            iter++;
        }
        io.writeLine(res+"");
    }

    class Bucket{
        public Bucket (int _k, List<List<Integer>> _list){
            k = _k;
            list = _list;
        }
       public int k;
        List<List<Integer>> list;
    }

}

class ConsoleIO {
    BufferedReader br;
    PrintWriter out;
    public ConsoleIO(Reader reader, PrintWriter writer){br = new BufferedReader(reader);out = writer;}
    public void flush(){this.out.flush();}
    public void close(){this.out.close();}
    public void writeLine(String s) {this.out.println(s);}
    public void writeInt(int a) {this.out.print(a);this.out.print(' ');}
    public void writeWord(String s){
        this.out.print(s);
    }
    public void writeIntArray(int[] a, int k, String separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < k; i++) {
            if (i > 0) sb.append(separator);
            sb.append(a[i]);
        }
        this.writeLine(sb.toString());
    }
    public int read(char[] buf, int len){try {return br.read(buf,0,len);}catch (Exception ex){ return -1; }}
    public String readLine() {try {return br.readLine();}catch (Exception ex){ return "";}}
    public long[] readLongArray() {
        String[]n=this.readLine().trim().split("\\s+");long[]r=new long[n.length];
        for(int i=0;i<n.length;i++)r[i]=Long.parseLong(n[i]);
        return r;
    }
    public int[] readIntArray() {
        String[]n=this.readLine().trim().split("\\s+");int[]r=new int[n.length];
        for(int i=0;i<n.length;i++)r[i]=Integer.parseInt(n[i]);
        return r;
    }
    public int[] readIntArray(int n) {
        int[] res = new int[n];
        char[] all = this.readLine().toCharArray();
        int cur = 0;boolean have = false;
        int k = 0;
        boolean neg = false;
        for(int i = 0;i<all.length;i++){
            if(all[i]>='0' && all[i]<='9'){
                cur = cur*10+all[i]-'0';
                have = true;
            }else if(all[i]=='-') {
                neg = true;
            }
            else if(have){
                res[k++] = neg?-cur:cur;
                cur = 0;
                have = false;
                neg = false;
            }
        }
        if(have)res[k++] = neg?-cur:cur;
        return res;
    }
    public int ri() {
        try {
            int r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public long readLong() {
        try {
            long r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public String readWord() {
        try {
            boolean start = false;
            StringBuilder sb = new StringBuilder();
            while (true) {
                int c = br.read();
                if (c!= ' ' && c!= '\r' && c!='\n' && c!='\t') {
                    sb.append((char)c);
                    start = true;
                } else if (start || c == -1) return sb.toString();
            }
        } catch (Exception ex) {
            return "";
        }
    }
    public char readSymbol() {
        try {
            while (true) {
                int c = br.read();
                if (c != ' ' && c != '\r' && c != '\n' && c != '\t') {
                    return (char) c;
                }
            }
        } catch (Exception ex) {
            return 0;
        }
    }
    public char readChar(){try {return (char)br.read();}catch (Exception ex){ return 0; }}
}