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 {
    private FastScanner in;
    private PrintWriter out;

    long[] fact = new long[1_000_001];
    long MOD = (int) 1e9 + 7;
    {
        fact[0] = 1;
        for (int i = 1; i < fact.length; i++) {
            fact[i] = fact[i - 1] * i;
            fact[i] %= MOD;
        }
    }

    private void solve() throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        int p = 1;
        int[] which = new int[1 + m];
        for (int i = 0; i < n; i++) {
            int[] a = in.nextInts(in.nextInt());
            Map<Integer, Integer> cnt = new HashMap<>();
            for (int e : a) {
                cnt.put(e, cnt.getOrDefault(e, 0) + 1);
            }
            Map<Integer, List<Integer>> groups = new HashMap<>();
            Set<Integer> sizes = new HashSet<>();
            for (int e : a) {
                int size = cnt.get(e);
                List<Integer> list = groups.get(size);
                if (list == null) {
                    sizes.add(size);
                    list = new ArrayList<>();
                    groups.put(size, list);
                }
                list.add(e);
            }
            for (Integer size : sizes) {
                List<Integer> group = groups.get(size);
                Map<Integer, List<Integer>> nextGroups = new HashMap<>();
                Set<Integer> kek = new HashSet<>();
                for (int e : group) {
                    List<Integer> list = nextGroups.get(which[e]);
                    if (list == null) {
                        kek.add(which[e]);
                        list = new ArrayList<>();
                        nextGroups.put(which[e], list);
                    }
                    list.add(e);
                }
                for (Integer group2 : kek) {
                    for (int e : nextGroups.get(group2)) {
                        which[e] = p;
                    }
                    p++;
                }
            }
        }
        Map<Integer, Integer> cnt = new HashMap<>();
        Set<Integer> whiches = new HashSet<>();

        for (int i = 1; i <= m; i++) {
            cnt.put(which[i], cnt.getOrDefault(which[i], 0) + 1);
            whiches.add(which[i]);
        }
        long answer = 1;
        for (Integer e : whiches) {
            answer *= fact[cnt.get(e)];
            answer %= MOD;
        }
        out.println(answer);
    }

    private void run() throws IOException {
        in = new FastScanner();
        out = new PrintWriter(System.out, false);
        while (in.hasNext()) {
            solve();
            out.flush();
        }
        out.close();
    }

    public static void main(String[] args) throws IOException {
//        Integer stackSize = null;
        Integer stackSize = 1 << 27; // 128mb

        if (stackSize != null) {
            new Thread(null, () -> {
                try {
                    new Main().run();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }, "", stackSize).start();
        } else {
            new Main().run();
        }
    }
}

class FastScanner {
    private final BufferedReader br;
    private StringTokenizer st;
    private String last;

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public FastScanner(String path) throws IOException {
        br = new BufferedReader(new FileReader(path));
    }

    public FastScanner(String path, String decoder) throws IOException {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(path), decoder));
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        last = null;
        return st.nextToken();
    }

    String nextLine() throws IOException {
        st = null;
        return (last == null) ? br.readLine() : last;
    }

    boolean hasNext() {
        if (st != null && st.hasMoreElements())
            return true;

        try {
            while (st == null || !st.hasMoreElements()) {
                last = br.readLine();
                st = new StringTokenizer(last);
            }
        } catch (Exception e) {
            return false;
        }

        return true;
    }

    String[] nextStrings(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = next();
        return arr;
    }

    String[] nextLines(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLine();
        return arr;
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    int[] nextInts(int n) throws IOException {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    Integer[] nextIntegers(int n) throws IOException {
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    int[][] next2Ints(int n, int m) throws IOException {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextInt();
        return arr;
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    long[] nextLongs(int n) throws IOException {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLong();
        return arr;
    }

    long[][] next2Longs(int n, int m) throws IOException {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextLong();
        return arr;
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next().replace(',', '.'));
    }

    double[] nextDoubles(int size) throws IOException {
        double[] arr = new double[size];
        for (int i = 0; i < size; i++)
            arr[i] = nextDouble();
        return arr;
    }

    boolean nextBool() throws IOException {
        String s = next();
        if (s.equalsIgnoreCase("true") || s.equals("1"))
            return true;

        if (s.equalsIgnoreCase("false") || s.equals("0"))
            return false;

        throw new IOException("Boolean expected, String found!");
    }

    public double[][] next2Doubles(int n, int m) throws IOException {
        double[][] arr = new double[n][];
        for (int i = 0; i < n; i++) {
            arr[i] = nextDoubles(m);
        }
        return arr;
    }
}
