1552_G. A Serious Referee_79
Andrea has come up with what he believes to be a novel sorting algorithm for arrays of length n. The algorithm works as follows.

Initially there is an array of n integers a_1,  a_2,  ...,  a_n. Then, k steps are executed.

For each 1≤ i≤ k, during the i-th step the subsequence of the array a with indexes j_{i,1}< j_{i,2}< ...< j_{i, q_i} is sorted, without changing the values with the remaining indexes. So, the subsequence a_{j_{i,1}},  a_{j_{i,2}},  ...,  a_{j_{i,q_i}} is sorted and all other elements of a are left untouched.

Andrea, being eager to share his discovery with the academic community, sent a short paper describing his algorithm to the journal "Annals of Sorting Algorithms" and you are the referee of the paper (that is, the person who must judge the correctness of the paper). You must decide whether Andrea's algorithm is correct, that is, if it sorts any array a of n integers.

Input

The first line contains two integers n and k (1≤ n≤ 40, 0≤ k≤ 10) — the length of the arrays handled by Andrea's algorithm and the number of steps of Andrea's algorithm.

Then k lines follow, each describing the subsequence considered in a step of Andrea's algorithm.

The i-th of these lines contains the integer q_i (1≤ q_i≤ n) followed by q_i integers j_{i,1},\,j_{i,2}, ...,  j_{i,q_i} (1≤ j_{i,1}<j_{i,2}<⋅⋅⋅<j_{i,q_i}≤ n) — the length of the subsequence considered in the i-th step and the indexes of the subsequence.

Output

If Andrea's algorithm is correct print ACCEPTED, otherwise print REJECTED.

Examples

Input


4 3
3 1 2 3
3 2 3 4
2 1 2


Output


ACCEPTED


Input


4 3
3 1 2 3
3 2 3 4
3 1 3 4


Output


REJECTED


Input


3 4
1 1
1 2
1 3
2 1 3


Output


REJECTED


Input


5 2
3 2 3 4
5 1 2 3 4 5


Output


ACCEPTED

Note

Explanation of the first sample: The algorithm consists of 3 steps. The first one sorts the subsequence [a_1, a_2, a_3], the second one sorts the subsequence [a_2, a_3, a_4], the third one sorts the subsequence [a_1,a_2]. For example, if initially a=[6, 5, 6, 3], the algorithm transforms the array as follows (the subsequence that gets sorted is highlighted in red) $$$ [{\color{red}6},{\color{red}5},{\color{red}6},3] → [5, {\color{red}6}, {\color{red}6}, {\color{red}3}] → [{\color{red}5}, {\color{red}3}, 6, 6] → [3, 5, 6, 6]  . One can prove that, for any initial array a, at the end of the algorithm the array a$$$ will be sorted.

Explanation of the second sample: The algorithm consists of 3 steps. The first one sorts the subsequence [a_1, a_2, a_3], the second one sorts the subsequence [a_2, a_3, a_4], the third one sorts the subsequence [a_1,a_3,a_4]. For example, if initially a=[6, 5, 6, 3], the algorithm transforms the array as follows (the subsequence that gets sorted is highlighted in red) $$$ [{\color{red}6},{\color{red}5},{\color{red}6},3] → [5, {\color{red}6}, {\color{red}6}, {\color{red}3}] → [{\color{red}5}, 3, {\color{red}6}, {\color{red}6}] → [5, 3, 6, 6]  . Notice that a=[6,5,6,3]$$$ is an example of an array that is not sorted by the algorithm.

Explanation of the third sample: The algorithm consists of 4 steps. The first 3 steps do nothing because they sort subsequences of length 1, whereas the fourth step sorts the subsequence [a_1,a_3]. For example, if initially a=[5,6,4], the algorithm transforms the array as follows (the subsequence that gets sorted is highlighted in red) $$$ [{\color{red}5},6,4] → [5,{\color{red}6},4] → [5,{\color{red}6},4] → [{\color{red}5},6,{\color{red}4}]→ [4,6,5]  . Notice that a=[5,6,4]$$$ is an example of an array that is not sorted by the algorithm.

Explanation of the fourth sample: The algorithm consists of 2 steps. The first step sorts the subsequences [a_2,a_3,a_4], the second step sorts the whole array [a_1,a_2,a_3,a_4,a_5]. For example, if initially a=[9,8,1,1,1], the algorithm transforms the array as follows (the subsequence that gets sorted is highlighted in red) $$$ [9,{\color{red}8},{\color{red}1},{\color{red}1},1] → [{\color{red}9},{\color{red}1},{\color{red}1},{\color{red}8},{\color{red}1}] → [1,1,1,8,9]  . Since in the last step the whole array is sorted, it is clear that, for any initial array a, at the end of the algorithm the array a$$$ will be sorted.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            GASeriousReferee solver = new GASeriousReferee();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class GASeriousReferee {
        int n;
        long[] S;
        long[][] sortedS;
        int[] delta;
        boolean ok = true;
        long whole;

        public void dfs(int i, long bitset) {
            if (!ok) {
                return;
            }
            if (i == S.length) {
                int bc = Long.bitCount(bitset);
                if (bitset != (~Bits.headLongMask(n - bc) & whole)) {
                    ok = false;
                }
                return;
            }
            int cur = Long.bitCount(bitset & S[i]);
            long cleanBitset = bitset & ~S[i];
            for (int j = 0; j <= delta[i]; j++) {
                dfs(i + 1, cleanBitset | sortedS[i][j + cur]);
            }
        }

        public void solve(int testNumber, FastInput in, FastOutput out) {
            n = in.ri();
            whole = (1L << n) - 1;
            int k = in.ri();
            S = new long[k];
            sortedS = new long[k][];
            delta = new int[k];
            long prev = 0;
            for (int i = 0; i < k; i++) {
                int q = in.ri();
                for (int j = 0; j < q; j++) {
                    int index = in.ri() - 1;
                    S[i] |= 1L << index;
                }
                sortedS[i] = new long[q + 1];
                long v = S[i];
                for (int j = 1; j <= q; j++) {
                    sortedS[i][j] = sortedS[i][j - 1];
                    long highest = Long.highestOneBit(v);
                    v -= highest;
                    sortedS[i][j] |= highest;
                }
                delta[i] = Long.bitCount(S[i] ^ (S[i] & prev));
                prev |= S[i];
            }
            if (prev != whole && n > 1) {
                ok = false;
            }
            dfs(0, 0);

            if (ok) {
                out.println("ACCEPTED");
            } else {
                out.println("REJECTED");
            }
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int ri() {
            return readInt();
        }

        public int readInt() {
            boolean rev = false;

            skipBlank();
            if (next == '+' || next == '-') {
                rev = next == '-';
                next = read();
            }

            int val = 0;
            while (next >= '0' && next <= '9') {
                val = val * 10 - next + '0';
                next = read();
            }

            return rev ? val : -val;
        }

    }

    static class Bits {
        private Bits() {
        }

        public static long headLongMask(int n) {
            if (n == 0) {
                return 0;
            }
            return -1L >>> (64 - n);
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private static final int THRESHOLD = 32 << 10;
        private OutputStream writer;
        private StringBuilder cache = new StringBuilder(THRESHOLD * 2);
        private static Field stringBuilderValueField;
        private char[] charBuf = new char[THRESHOLD * 2];
        private byte[] byteBuf = new byte[THRESHOLD * 2];

        static {
            try {
                stringBuilderValueField = StringBuilder.class.getSuperclass().getDeclaredField("value");
                stringBuilderValueField.setAccessible(true);
            } catch (Exception e) {
                stringBuilderValueField = null;
            }
            stringBuilderValueField = null;
        }

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        private void afterWrite() {
            if (cache.length() < THRESHOLD) {
                return;
            }
            flush();
        }

        public FastOutput(OutputStream writer) {
            this.writer = writer;
        }

        public FastOutput append(char c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput append(String c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput println(String c) {
            return append(c).println();
        }

        public FastOutput println() {
            return append('\n');
        }

        public FastOutput flush() {
            try {
                if (stringBuilderValueField != null) {
                    try {
                        byte[] value = (byte[]) stringBuilderValueField.get(cache);
                        writer.write(value, 0, cache.length());
                    } catch (Exception e) {
                        stringBuilderValueField = null;
                    }
                }
                if (stringBuilderValueField == null) {
                    int n = cache.length();
                    if (n > byteBuf.length) {
                        //slow
                        writer.write(cache.toString().getBytes(StandardCharsets.UTF_8));
//                writer.append(cache);
                    } else {
                        cache.getChars(0, n, charBuf, 0);
                        for (int i = 0; i < n; i++) {
                            byteBuf[i] = (byte) charBuf[i];
                        }
                        writer.write(byteBuf, 0, n);
                    }
                }
                writer.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                writer.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }
}

