import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        int totalNode;
        int[] aNext;
        int[] bNext;
        int[] fail;
        int[] id;
        int[] nearest;
        boolean[][] g;
        ArrayList<Integer>[] edg;
        boolean[] vis;
        BitSet[] bs;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            char[][] s = new char[n][];
            int totalLength = 0;
            for (int i = 0; i < n; ++i) {
                s[i] = in.next().toCharArray();
                totalLength += s[i].length;
            }
            aNext = new int[totalLength + 1];
            bNext = new int[totalLength + 1];
            id = new int[totalLength + 1];
            Arrays.fill(id, -1);
            totalNode = 1;
            for (int i = 0; i < n; ++i) {
                insert(s[i], i);
            }
            if (totalLength >= 1e7) return;
            fail = new int[totalLength + 1];
            nearest = new int[totalLength + 1];
            Arrays.fill(nearest, -1);
            build();
            edg = new ArrayList[n];
            for (int i = 0; i < n; ++i) {
                edg[i] = new ArrayList<Integer>();
            }
            for (int i = 0; i < n; ++i) {
                go(s[i], i);
            }
            g = new boolean[n][n];
            vis = new boolean[n];
            bs = new BitSet[n];
            for (int i = 0; i < n; ++i) {
                bs[i] = new BitSet(n);
            }
            for (int i = 0; i < n; ++i) {
                if (vis[i]) continue;
                dfs(i);
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    g[i][j] = bs[i].test(j);
                }
            }
            BM sol = new BM(n, g);
            ArrayList<Integer> ans = sol.solve();
            out.println(ans.size());
            for (int i = 0; i < ans.size(); ++i) {
                out.print(ans.get(i) + 1);
                if (i + 1 == ans.size()) {
                    out.print('\n');
                } else {
                    out.print(' ');
                }
            }
        }

        void dfs(int u) {
            vis[u] = true;
            for (int i = 0; i < edg[u].size(); ++i) {
                int v = edg[u].get(i);
                if (!vis[v]) {
                    dfs(v);
                }
                bs[u].set(v);
                bs[u] = bs[u].or(bs[v]);
            }
        }

        void insert(char[] s, int _id) {
            int crt = 0;
            for (int i = 0; i < s.length; ++i) {
                int[] next = s[i] == 'a' ? aNext : bNext;
                if (next[crt] == 0) {
                    next[crt] = totalNode++;
                }
                crt = next[crt];
            }
            id[crt] = _id;
        }

        void build() {
            int[] q = new int[totalNode];
            q[0] = 0;
            for (int h = 0, t = 1; h < t; ++h) {
                int u = q[h];
                if (id[u] >= 0) {
                    nearest[u] = id[u];
                } else {
                    nearest[u] = nearest[fail[u]];
                }
                for (char ch = 'a'; ch < 'c'; ++ch) {
                    int[] next = (ch == 'a' ? aNext : bNext);
                    if (next[u] > 0) {
                        q[t++] = next[u];
                        if (u == 0) continue;
                        int j = fail[u];
                        while (j > 0 && next[j] == 0) {
                            j = next[j];
                        }
                        if (next[j] > 0) {
                            fail[next[u]] = next[j];
                        }
                    }
                }
            }
        }

        void go(char[] s, int _id) {
            int crt = 0;
            for (int i = 0; i < s.length; ++i) {
                int[] next = (s[i] == 'a' ? aNext : bNext);
                crt = next[crt];
                if (id[crt] == _id) {
                    if (nearest[fail[crt]] >= 0) {
                        addEdge(nearest[fail[crt]], _id);
                    }
                } else {
                    if (nearest[crt] >= 0) {
                        addEdge(nearest[crt], _id);
                    }
                }
            }
        }

        void addEdge(int u, int v) {
            edg[u].add(v);
        }

        class BM {
            int n;
            ArrayList<Integer>[] edg;
            boolean[] vis;
            int[] x;
            int[] y;
            ArrayList<Integer> ans;

            public BM(int n, boolean[][] g) {
                this.n = n;
                edg = new ArrayList[n];
                for (int i = 0; i < n; ++i) {
                    edg[i] = new ArrayList<Integer>();
                    for (int j = 0; j < n; ++j) {
                        if (g[i][j]) {
                            edg[i].add(j);
                        }
                    }
                }
                vis = new boolean[n];
                x = new int[n];
                y = new int[n];
                ans = new ArrayList<Integer>();
            }

            public ArrayList<Integer> solve() {
                int cnt = 0;
                Arrays.fill(x, -1);
                Arrays.fill(y, -1);
                boolean[] chs = new boolean[n + n];
                for (int i = 0; i < n; ++i) {
                    Arrays.fill(vis, false);
                    if (dfs(i)) {
                        ++cnt;
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (x[i] != -1) {
                        chs[i] = true;
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (x[i] == -1) {
                        for (int j = 0; j < edg[i].size(); ++j) {
                            int v = edg[i].get(j);
                            chs[n + v] = true;
                            chs[y[v]] = false;
                        }
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (!chs[i] && !chs[i + n]) {
                        ans.add(i);
                    }
                }
                if (ans.size() != n - cnt) {
                    throw new RuntimeException();
                }
                return ans;
            }

            boolean dfs(int u) {
                for (int i = 0; i < edg[u].size(); ++i) {
                    int v = edg[u].get(i);
                    if (!vis[v]) {
                        vis[v] = true;
                        if (y[v] == -1 || dfs(y[v])) {
                            x[u] = v;
                            y[v] = u;
                            return true;
                        }
                    }
                }
                return false;
            }

        }

    }

    static class BitSet {
        int len;
        int size;
        long[] bit;

        public BitSet(int len) {
            this.len = len;
            size = len + 63 >> 6;
            bit = new long[size];
        }

        public BitSet or(BitSet a) {
            BitSet ret = new BitSet(len);
            for (int i = 0; i < size; ++i) {
                ret.bit[i] = bit[i] | a.bit[i];
            }
            return ret;
        }

        public boolean test(int pos) {
            return (bit[pos >> 6] >> (pos & 63) & 1) > 0;
        }

        public void set(int pos) {
            bit[pos >> 6] |= 1L << (pos & 63);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Queue;
import java.util.LinkedList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        int N;
        Node[] tree;
        boolean[][] g;
        ArrayList<Integer>[] edg;
        boolean[] vis;
        BitSet[] bs;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            char[][] s = new char[n][];
            int totalLength = 0;
            for (int i = 0; i < n; ++i) {
                s[i] = in.next().toCharArray();
                totalLength += s[i].length;
            }
            if (totalLength >= 1e7) return;
            tree = new Node[totalLength + 1];
            tree[0] = new Node();
            N = 1;
            for (int i = 0; i < n; ++i) {
                insert(s[i], i);
            }
            build();
            edg = new ArrayList[n];
            for (int i = 0; i < n; ++i) {
                edg[i] = new ArrayList<Integer>();
            }
            for (int i = 0; i < n; ++i) {
                go(s[i], i);
            }

            g = new boolean[n][n];
            vis = new boolean[n];
            bs = new BitSet[n];
            for (int i = 0; i < n; ++i) {
                bs[i] = new BitSet(n);
            }
            for (int i = 0; i < n; ++i) {
                if (vis[i]) continue;
                dfs(i);
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    g[i][j] = bs[i].test(j);
                }
            }
            BM sol = new BM(n, g);
            ArrayList<Integer> ans = sol.solve();
            out.println(ans.size());
            for (int i = 0; i < ans.size(); ++i) {
                out.print(ans.get(i) + 1);
                if (i + 1 == ans.size()) {
                    out.print('\n');
                } else {
                    out.print(' ');
                }
            }
        }

        void dfs(int u) {
            vis[u] = true;
            for (int i = 0; i < edg[u].size(); ++i) {
                int v = edg[u].get(i);
                if (!vis[v]) {
                    dfs(v);
                }
                bs[u].set(v);
                bs[u] = bs[u].or(bs[v]);
            }
        }

        void insert(char[] s, int id) {
            int crt = 0;
            for (int i = 0; i < s.length; ++i) {
                int ch = s[i] - 'a';
                if (tree[crt].nxt[ch] == 0) {
                    tree[crt].nxt[ch] = N++;
                    tree[N - 1] = new Node();
                }
                crt = tree[crt].nxt[ch];
            }
            tree[crt].id = id;
        }

        void build() {
            Queue<Integer> Q = new LinkedList<Integer>();
            Q.offer(0);
            while (!Q.isEmpty()) {
                int u = Q.poll();
                if (tree[u].id >= 0) {
                    tree[u].nearest = tree[u].id;
                } else {
                    tree[u].nearest = tree[tree[u].fail].nearest;
                }
                for (int i = 0; i < 2; ++i) {
                    if (tree[u].nxt[i] > 0) {
                        Q.offer(tree[u].nxt[i]);
                        if (u == 0) continue;
                        int j = tree[u].fail;
                        while (j > 0 && tree[j].nxt[i] == 0) {
                            j = tree[j].fail;
                        }
                        if (tree[j].nxt[i] > 0) {
                            tree[tree[u].nxt[i]].fail = tree[j].nxt[i];
                        }
                    }
                }
            }
        }

        void go(char[] s, int id) {
            int crt = 0;
            for (int i = 0; i < s.length; ++i) {
                int ch = s[i] - 'a';
                crt = tree[crt].nxt[ch];
                if (tree[crt].id == id) {
                    if (tree[tree[crt].fail].nearest >= 0) {
                        addEdge(tree[tree[crt].fail].nearest, id);
                    }
                } else {
                    if (tree[crt].nearest >= 0) {
                        addEdge(tree[crt].nearest, id);
                    }
                }
            }
        }

        void addEdge(int u, int v) {
            edg[u].add(v);
        }

        class Node {
            int fail;
            int[] nxt;
            int id;
            int nearest;

            public Node() {
                fail = 0;
                id = nearest = -1;
                nxt = new int[2];
            }

        }

        class BM {
            int n;
            ArrayList<Integer>[] edg;
            boolean[] vis;
            int[] x;
            int[] y;
            ArrayList<Integer> ans;

            public BM(int n, boolean[][] g) {
                this.n = n;
                edg = new ArrayList[n];
                for (int i = 0; i < n; ++i) {
                    edg[i] = new ArrayList<Integer>();
                    for (int j = 0; j < n; ++j) {
                        if (g[i][j]) {
                            edg[i].add(j);
                        }
                    }
                }
                vis = new boolean[n];
                x = new int[n];
                y = new int[n];
                ans = new ArrayList<Integer>();
            }

            public ArrayList<Integer> solve() {
                int cnt = 0;
                Arrays.fill(x, -1);
                Arrays.fill(y, -1);
                boolean[] chs = new boolean[n + n];
                for (int i = 0; i < n; ++i) {
                    Arrays.fill(vis, false);
                    if (dfs(i)) {
                        ++cnt;
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (x[i] != -1) {
                        chs[i] = true;
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (x[i] == -1) {
                        for (int j = 0; j < edg[i].size(); ++j) {
                            int v = edg[i].get(j);
                            chs[n + v] = true;
                            chs[y[v]] = false;
                        }
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (!chs[i] && !chs[i + n]) {
                        ans.add(i);
                    }
                }
                if (ans.size() != n - cnt) {
                    throw new RuntimeException();
                }
                return ans;
            }

            boolean dfs(int u) {
                for (int i = 0; i < edg[u].size(); ++i) {
                    int v = edg[u].get(i);
                    if (!vis[v]) {
                        vis[v] = true;
                        if (y[v] == -1 || dfs(y[v])) {
                            x[u] = v;
                            y[v] = u;
                            return true;
                        }
                    }
                }
                return false;
            }

        }

    }

    static class BitSet {
        int len;
        int size;
        long[] bit;

        public BitSet(int len) {
            this.len = len;
            size = len + 63 >> 6;
            bit = new long[size];
        }

        public BitSet or(BitSet a) {
            BitSet ret = new BitSet(len);
            for (int i = 0; i < size; ++i) {
                ret.bit[i] = bit[i] | a.bit[i];
            }
            return ret;
        }

        public boolean test(int pos) {
            return (bit[pos >> 6] >> (pos & 63) & 1) > 0;
        }

        public void set(int pos) {
            bit[pos >> 6] |= 1L << (pos & 63);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        int totalNode;
        int[] aNext;
        int[] bNext;
        int[] fail;
        int[] id;
        int[] nearest;
        boolean[][] g;
        ArrayList<Integer>[] edg;
        boolean[] vis;
        BitSet[] bs;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            char[][] s = new char[n][];
            int totalLength = 0;
            for (int i = 0; i < n; ++i) {
                s[i] = in.next().toCharArray();
                totalLength += s[i].length;
            }
            aNext = new int[totalLength + 1];
            bNext = new int[totalLength + 1];
            id = new int[totalLength + 1];
            Arrays.fill(id, -1);
            totalNode = 1;
            for (int i = 0; i < n; ++i) {
                insert(s[i], i);
            }
            fail = new int[totalLength + 1];
            nearest = new int[totalLength + 1];
            Arrays.fill(nearest, -1);
            build();
            edg = new ArrayList[n];
            for (int i = 0; i < n; ++i) {
                edg[i] = new ArrayList<Integer>();
            }
            for (int i = 0; i < n; ++i) {
                go(s[i], i);
            }
            g = new boolean[n][n];
            vis = new boolean[n];
            bs = new BitSet[n];
            for (int i = 0; i < n; ++i) {
                bs[i] = new BitSet(n);
            }
            for (int i = 0; i < n; ++i) {
                if (vis[i]) continue;
                dfs(i);
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    g[i][j] = bs[i].test(j);
                }
            }
            BM sol = new BM(n, g);
            ArrayList<Integer> ans = sol.solve();
            out.println(ans.size());
            for (int i = 0; i < ans.size(); ++i) {
                out.print(ans.get(i) + 1);
                if (i + 1 == ans.size()) {
                    out.print('\n');
                } else {
                    out.print(' ');
                }
            }
        }

        void dfs(int u) {
            vis[u] = true;
            for (int i = 0; i < edg[u].size(); ++i) {
                int v = edg[u].get(i);
                if (!vis[v]) {
                    dfs(v);
                }
                bs[u].set(v);
                bs[u] = bs[u].or(bs[v]);
            }
        }

        void insert(char[] s, int _id) {
            int crt = 0;
            for (int i = 0; i < s.length; ++i) {
                int[] next = (s[i] == 'a' ? aNext : bNext);
                if (next[crt] == 0) {
                    next[crt] = totalNode++;
                }
                crt = next[crt];
            }
            id[crt] = _id;
        }

        void build() {
            int[] q = new int[totalNode];
            q[0] = 0;
            for (int h = 0, t = 1; h < t; ++h) {
                int u = q[h];
                if (id[u] >= 0) {
                    nearest[u] = id[u];
                } else {
                    nearest[u] = nearest[fail[u]];
                }
                for (int i = 0; i < 2; ++i) {
                    int[] next = (i == 0 ? aNext : bNext);
                    if (next[u] > 0) {
                        q[t++] = next[u];
                        if (u == 0) continue;
                        int j = fail[u];
                        while (j > 0 && next[j] == 0) {
                            j = fail[j];
                        }
                        if (next[j] > 0) {
                            fail[next[u]] = next[j];
                        }
                    }
                }
            }
        }

        void go(char[] s, int _id) {
            int crt = 0;
            for (int i = 0; i < s.length; ++i) {
                int[] next = (s[i] == 'a' ? aNext : bNext);
                crt = next[crt];
                if (id[crt] == _id) {
                    if (nearest[fail[crt]] >= 0) {
                        addEdge(nearest[fail[crt]], _id);
                    }
                } else {
                    if (nearest[crt] >= 0) {
                        addEdge(nearest[crt], _id);
                    }
                }
            }
        }

        void addEdge(int u, int v) {
            edg[u].add(v);
        }

        class BM {
            int n;
            ArrayList<Integer>[] edg;
            boolean[] vis;
            boolean[] chs;
            int[] x;
            int[] y;
            ArrayList<Integer> ans;

            public BM(int n, boolean[][] g) {
                this.n = n;
                edg = new ArrayList[n];
                for (int i = 0; i < n; ++i) {
                    edg[i] = new ArrayList<Integer>();
                    for (int j = 0; j < n; ++j) {
                        if (g[i][j]) {
                            edg[i].add(j);
                        }
                    }
                }
                vis = new boolean[n];
                chs = new boolean[n + n];
                x = new int[n];
                y = new int[n];
                ans = new ArrayList<Integer>();
            }

            public ArrayList<Integer> solve() {
                int cnt = 0;
                Arrays.fill(x, -1);
                Arrays.fill(y, -1);
                for (int i = 0; i < n; ++i) {
                    Arrays.fill(vis, false);
                    if (dfs(i)) {
                        ++cnt;
                    }
                }
                Arrays.fill(chs, false);
                for (int i = 0; i < n; ++i) {
                    if (x[i] != -1) {
                        chs[i] = true;
                    }
                }
                Arrays.fill(vis, false);
                for (int i = 0; i < n; ++i) {
                    if (x[i] == -1 && !vis[i]) {
                        go(i);
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (!chs[i] && !chs[i + n]) {
                        ans.add(i);
                    }
                }
                if (ans.size() != n - cnt) {
                    throw new RuntimeException();
                }
                return ans;
            }

            void go(int u) {
                vis[u] = true;
                chs[u] = false;
                for (int i = 0; i < edg[u].size(); ++i) {
                    int v = edg[u].get(i);
                    chs[n + v] = true;
                    if (!vis[y[v]]) {
                        go(y[v]);
                    }
                }
            }

            boolean dfs(int u) {
                for (int i = 0; i < edg[u].size(); ++i) {
                    int v = edg[u].get(i);
                    if (!vis[v]) {
                        vis[v] = true;
                        if (y[v] == -1 || dfs(y[v])) {
                            x[u] = v;
                            y[v] = u;
                            return true;
                        }
                    }
                }
                return false;
            }

        }

    }

    static class BitSet {
        int len;
        int size;
        long[] bit;

        public BitSet(int len) {
            this.len = len;
            size = len + 63 >> 6;
            bit = new long[size];
        }

        public BitSet or(BitSet a) {
            BitSet ret = new BitSet(len);
            for (int i = 0; i < size; ++i) {
                ret.bit[i] = bit[i] | a.bit[i];
            }
            return ret;
        }

        public boolean test(int pos) {
            return (bit[pos >> 6] >> (pos & 63) & 1) > 0;
        }

        public void set(int pos) {
            bit[pos >> 6] |= 1L << (pos & 63);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        int totalNode;
        int[] aNext;
        int[] bNext;
        int[] fail;
        int[] id;
        int[] nearest;
        boolean[][] g;
        ArrayList<Integer>[] edg;
        boolean[] vis;
        BitSet[] bs;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            char[][] s = new char[n][];
            int totalLength = 0;
            for (int i = 0; i < n; ++i) {
                s[i] = in.next().toCharArray();
                totalLength += s[i].length;
            }
            aNext = new int[totalLength + 1];
            bNext = new int[totalLength + 1];
            id = new int[totalLength + 1];
            Arrays.fill(id, -1);
            totalNode = 1;
            for (int i = 0; i < n; ++i) {
                insert(s[i], i);
            }
            fail = new int[totalLength + 1];
            nearest = new int[totalLength + 1];
            Arrays.fill(nearest, -1);
            build();
            edg = new ArrayList[n];
            for (int i = 0; i < n; ++i) {
                edg[i] = new ArrayList<Integer>();
            }
            for (int i = 0; i < n; ++i) {
                go(s[i], i);
            }
            g = new boolean[n][n];
            vis = new boolean[n];
            bs = new BitSet[n];
            for (int i = 0; i < n; ++i) {
                bs[i] = new BitSet(n);
            }
            for (int i = 0; i < n; ++i) {
                if (vis[i]) continue;
                dfs(i);
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    g[i][j] = bs[i].test(j);
                }
            }
            BM sol = new BM(n, g);
            ArrayList<Integer> ans = sol.solve();
            out.println(ans.size());
            for (int i = 0; i < ans.size(); ++i) {
                out.print(ans.get(i) + 1);
                if (i + 1 == ans.size()) {
                    out.print('\n');
                } else {
                    out.print(' ');
                }
            }
        }

        void dfs(int u) {
            vis[u] = true;
            for (int i = 0; i < edg[u].size(); ++i) {
                int v = edg[u].get(i);
                if (!vis[v]) {
                    dfs(v);
                }
                bs[u].set(v);
                bs[u] = bs[u].or(bs[v]);
            }
        }

        void insert(char[] s, int _id) {
            int crt = 0;
            for (int i = 0; i < s.length; ++i) {
                int[] next = (s[i] == 'a' ? aNext : bNext);
                if (next[crt] == 0) {
                    next[crt] = totalNode++;
                }
                crt = next[crt];
            }
            id[crt] = _id;
        }

        void build() {
            int[] q = new int[totalNode];
            q[0] = 0;
            for (int h = 0, t = 1; h < t; ++h) {
                int u = q[h];
                if (id[u] >= 0) {
                    nearest[u] = id[u];
                } else {
                    nearest[u] = nearest[fail[u]];
                }
                for (int i = 0; i < 2; ++i) {
                    int[] next = (i == 0 ? aNext : bNext);
                    if (next[u] > 0) {
                        q[t++] = next[u];
                        if (u == 0) continue;
                        int j = fail[u];
                        while (j > 0 && next[j] == 0) {
                            j = next[j];
                        }
                        if (next[j] > 0) {
                            fail[next[u]] = next[j];
                        }
                    }
                }
            }
        }

        void go(char[] s, int _id) {
            int crt = 0;
            for (int i = 0; i < s.length; ++i) {
                int[] next = (s[i] == 'a' ? aNext : bNext);
                crt = next[crt];
                if (id[crt] == _id) {
                    if (nearest[fail[crt]] >= 0) {
                        addEdge(nearest[fail[crt]], _id);
                    }
                } else {
                    if (nearest[crt] >= 0) {
                        addEdge(nearest[crt], _id);
                    }
                }
            }
        }

        void addEdge(int u, int v) {
            edg[u].add(v);
        }

        class BM {
            int n;
            ArrayList<Integer>[] edg;
            boolean[] vis;
            int[] x;
            int[] y;
            ArrayList<Integer> ans;

            public BM(int n, boolean[][] g) {
                this.n = n;
                edg = new ArrayList[n];
                for (int i = 0; i < n; ++i) {
                    edg[i] = new ArrayList<Integer>();
                    for (int j = 0; j < n; ++j) {
                        if (g[i][j]) {
                            edg[i].add(j);
                        }
                    }
                }
                vis = new boolean[n];
                x = new int[n];
                y = new int[n];
                ans = new ArrayList<Integer>();
            }

            public ArrayList<Integer> solve() {
                int cnt = 0;
                Arrays.fill(x, -1);
                Arrays.fill(y, -1);
                boolean[] chs = new boolean[n + n];
                for (int i = 0; i < n; ++i) {
                    Arrays.fill(vis, false);
                    if (dfs(i)) {
                        ++cnt;
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (x[i] != -1) {
                        chs[i] = true;
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (x[i] == -1) {
                        for (int j = 0; j < edg[i].size(); ++j) {
                            int v = edg[i].get(j);
                            chs[n + v] = true;
                            chs[y[v]] = false;
                        }
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (!chs[i] && !chs[i + n]) {
                        ans.add(i);
                    }
                }
                if (ans.size() != n - cnt) {
                    throw new RuntimeException();
                }
                return ans;
            }

            boolean dfs(int u) {
                for (int i = 0; i < edg[u].size(); ++i) {
                    int v = edg[u].get(i);
                    if (!vis[v]) {
                        vis[v] = true;
                        if (y[v] == -1 || dfs(y[v])) {
                            x[u] = v;
                            y[v] = u;
                            return true;
                        }
                    }
                }
                return false;
            }

        }

    }

    static class BitSet {
        int len;
        int size;
        long[] bit;

        public BitSet(int len) {
            this.len = len;
            size = len + 63 >> 6;
            bit = new long[size];
        }

        public BitSet or(BitSet a) {
            BitSet ret = new BitSet(len);
            for (int i = 0; i < size; ++i) {
                ret.bit[i] = bit[i] | a.bit[i];
            }
            return ret;
        }

        public boolean test(int pos) {
            return (bit[pos >> 6] >> (pos & 63) & 1) > 0;
        }

        public void set(int pos) {
            bit[pos >> 6] |= 1L << (pos & 63);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        int totalNode;
        int[] aNext;
        int[] bNext;
        int[] fail;
        int[] id;
        int[] nearest;
        boolean[][] g;
        ArrayList<Integer>[] edg;
        boolean[] vis;
        BitSet[] bs;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            char[][] s = new char[n][];
            int totalLength = 0;
            for (int i = 0; i < n; ++i) {
                s[i] = in.next().toCharArray();
                totalLength += s[i].length;
            }
            aNext = new int[totalLength + 1];
            bNext = new int[totalLength + 1];
            id = new int[totalLength + 1];
            Arrays.fill(id, -1);
            totalNode = 1;
            for (int i = 0; i < n; ++i) {
                insert(s[i], i);
            }
            fail = new int[totalLength + 1];
            nearest = new int[totalLength + 1];
            Arrays.fill(nearest, -1);
            build();
            edg = new ArrayList[n];
            for (int i = 0; i < n; ++i) {
                edg[i] = new ArrayList<Integer>();
            }
            for (int i = 0; i < n; ++i) {
                go(s[i], i);
            }
            g = new boolean[n][n];
            vis = new boolean[n];
            bs = new BitSet[n];
            for (int i = 0; i < n; ++i) {
                bs[i] = new BitSet(n);
            }
            for (int i = 0; i < n; ++i) {
                if (vis[i]) continue;
                dfs(i);
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    g[i][j] = bs[i].test(j);
                }
            }
            BM sol = new BM(n, g);
            ArrayList<Integer> ans = sol.solve();
            out.println(ans.size());
            for (int i = 0; i < ans.size(); ++i) {
                out.print(ans.get(i) + 1);
                if (i + 1 == ans.size()) {
                    out.print('\n');
                } else {
                    out.print(' ');
                }
            }
        }

        void dfs(int u) {
            vis[u] = true;
            for (int i = 0; i < edg[u].size(); ++i) {
                int v = edg[u].get(i);
                if (!vis[v]) {
                    dfs(v);
                }
                bs[u].set(v);
                bs[u] = bs[u].or(bs[v]);
            }
        }

        void insert(char[] s, int _id) {
            int crt = 0;
            for (int i = 0; i < s.length; ++i) {
                int[] next = (s[i] == 'a' ? aNext : bNext);
                if (next[crt] == 0) {
                    next[crt] = totalNode++;
                }
                crt = next[crt];
            }
            id[crt] = _id;
        }

        void build() {
            int[] q = new int[totalNode];
            q[0] = 0;
            for (int h = 0, t = 1; h < t; ++h) {
                int u = q[h];
                if (id[u] >= 0) {
                    nearest[u] = id[u];
                } else {
                    nearest[u] = nearest[fail[u]];
                }
                for (int i = 0; i < 2; ++i) {
                    int[] next = (i == 0 ? aNext : bNext);
                    if (next[u] > 0) {
                        q[t++] = next[u];
                        if (u == 0) continue;
                        int j = fail[u];
                        while (j > 0 && next[j] == 0) {
                            j = fail[j];
                        }
                        if (next[j] > 0) {
                            fail[next[u]] = next[j];
                        }
                    }
                }
            }
        }

        void go(char[] s, int _id) {
            int crt = 0;
            for (int i = 0; i < s.length; ++i) {
                int[] next = (s[i] == 'a' ? aNext : bNext);
                crt = next[crt];
                if (id[crt] == _id) {
                    if (nearest[fail[crt]] >= 0) {
                        addEdge(nearest[fail[crt]], _id);
                    }
                } else {
                    if (nearest[crt] >= 0) {
                        addEdge(nearest[crt], _id);
                    }
                }
            }
        }

        void addEdge(int u, int v) {
            edg[u].add(v);
        }

        class BM {
            int n;
            ArrayList<Integer>[] edg;
            boolean[] vis;
            int[] x;
            int[] y;
            ArrayList<Integer> ans;

            public BM(int n, boolean[][] g) {
                this.n = n;
                edg = new ArrayList[n];
                for (int i = 0; i < n; ++i) {
                    edg[i] = new ArrayList<Integer>();
                    for (int j = 0; j < n; ++j) {
                        if (g[i][j]) {
                            edg[i].add(j);
                        }
                    }
                }
                vis = new boolean[n];
                x = new int[n];
                y = new int[n];
                ans = new ArrayList<Integer>();
            }

            public ArrayList<Integer> solve() {
                int cnt = 0;
                Arrays.fill(x, -1);
                Arrays.fill(y, -1);
                boolean[] chs = new boolean[n + n];
                for (int i = 0; i < n; ++i) {
                    Arrays.fill(vis, false);
                    if (dfs(i)) {
                        ++cnt;
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (x[i] != -1) {
                        chs[i] = true;
                        if (n - cnt == 12 && i == 15) {
                            System.out.println("x[" + i + "]=" + x[i]);
                            System.out.println("y[" + x[i] + "]=" + y[x[i]]);
                        }
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (x[i] == -1) {
                        for (int j = 0; j < edg[i].size(); ++j) {
                            int v = edg[i].get(j);
                            if (n - cnt == 12) {
                                if (v == 51) {
                                    if (y[v] != 15) {
                                        System.out.println(x[15] + ", " + y[51]);
                                        throw new RuntimeException();
                                    }
                                }
                                if (v == 40) {
                                    if (y[v] != 51) {
                                        System.out.println(x[51] + ", " + y[40]);
                                        throw new ArrayIndexOutOfBoundsException();
                                    }
                                }
                            }
                            chs[n + v] = true;
                            chs[y[v]] = false;
                        }
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (!chs[i] && !chs[i + n]) {
                        ans.add(i);
                    }
                }
                if (ans.size() != n - cnt) {
                    throw new RuntimeException();
                }
                return ans;
            }

            boolean dfs(int u) {
                for (int i = 0; i < edg[u].size(); ++i) {
                    int v = edg[u].get(i);
                    if (!vis[v]) {
                        vis[v] = true;
                        if (y[v] == -1 || dfs(y[v])) {
                            x[u] = v;
                            y[v] = u;
                            return true;
                        }
                    }
                }
                return false;
            }

        }

    }

    static class BitSet {
        int len;
        int size;
        long[] bit;

        public BitSet(int len) {
            this.len = len;
            size = len + 63 >> 6;
            bit = new long[size];
        }

        public BitSet or(BitSet a) {
            BitSet ret = new BitSet(len);
            for (int i = 0; i < size; ++i) {
                ret.bit[i] = bit[i] | a.bit[i];
            }
            return ret;
        }

        public boolean test(int pos) {
            return (bit[pos >> 6] >> (pos & 63) & 1) > 0;
        }

        public void set(int pos) {
            bit[pos >> 6] |= 1L << (pos & 63);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}


#include <bits/stdc++.h>
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 111;
int k[N], f[N];
int n, m;

int main() {
    ios::sync_with_stdio(false);
    cout.precision(10);
    cin >> n >> m;
    if(!m) {
        cout << (n == 1 ? 1 : -1) << endl;
        return 0;
    }
    for(int i = 1; i <= m; i++) {
        cin >> k[i] >> f[i];
    }
    set<int> ans;
    for(int nf = 1; nf <= 100; nf++) {
        bool ok = true;
        for(int i = 1; i <= m; i++) {
            int floor = (k[i] - 1) / nf + 1;
            if(floor != f[i]) {
                ok = false;
                break;
            }
        }
        if(ok) {
            ans.insert((n - 1) / nf + 1);
        }
    }
    if(ans.size() != 1) {
        cout << -1 << endl;
        return 0;
    }
    cout << *(ans.begin()) << endl;
    return 0;
}


#include <bits/stdc++.h>

//-----------------------------------------------------
/// SOL
///
///
//-----------------------------------------------------

#define up(i , a , b) for(int i = a ; i <= b; ++i)
#define up2(i , a , b , c) for(int i = a ; i <= b; i += c)
#define down(i , a , b) for (int i = a; i >= b; --i)
#define down2(i , a , b , c) for (int i = a; i >= b; i -= c)

#define II pair <int, int>
#define III pair<int, pair<int, int> >

#define pb push_back
#define mp make_pair

#define endl '\n'
#define TITLE "B"

#define gc getchar
#define pc putchar
#define length Len

//-----------------------------------------------------

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

const int N = 223;
const int oo = 1000000000;
bool DEBUG = 1;
ll n, m, f[N], k[N], MAX = 0;

struct T
{

};

void Init()
{
    cin >> n >> m;
    if(m == 0 && n == 1) {cout << 1; exit(0);}
    memset(f , 0 , sizeof(f));
    up(i , 1 , m)
        cin >> f[i] >> k[i], MAX = max(MAX , f[i]);
}

bool ok(ll flat)
{
    up(i , 1 , m) {
        bool z = 0;
        if((k[i] - 1) * flat < f[i] && f[i] <= (k[i] * flat)) z = 1;
        if(!z) return false;
    }
    return true;
}

void Solve()
{
    ll L = 1, H = 100, res = -1, res2 = -1;

    up(i , 1 , 100) {

        if(ok(i))
            if(res != -1) {cout << -1; exit(0);}
            else res = i;
    }

    ll ans = n / res;
    //cout << n << " " << res << " " << ans << " ";
    if(n > res * ans && res != -1) ans++;

    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

  //  freopen(TITLE".INP", "r", stdin);
  //  freopen(TITLE".OUT", "w", stdout);

    int Test = 1;
    //cin >> Test;
    up(i , 1 , Test) {
        Init();
        Solve();
    }
}

/*
/// ***************************** FAST I/O *****************************
inline void read(long long &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

inline void writeln(long long x)
{
     char buffor[21];
     register int i=0;
     int neg=0; if (x<0) {neg=1; x= -x;}
     do{
           buffor[i++]=(x%10)+'0';
           x/=10;
        } while(x);
       i--;
       if (neg) pc('-');
       while(i>=0) pc(buffor[i--]);
       pc('\n');
}
/// ***************************** FAST I/O *****************************
*/


#include <bits/stdc++.h>

//-----------------------------------------------------
/// SOL
///
///
//-----------------------------------------------------

#define up(i , a , b) for(int i = a ; i <= b; ++i)
#define up2(i , a , b , c) for(int i = a ; i <= b; i += c)
#define down(i , a , b) for (int i = a; i >= b; --i)
#define down2(i , a , b , c) for (int i = a; i >= b; i -= c)

#define II pair <int, int>
#define III pair<int, pair<int, int> >

#define pb push_back
#define mp make_pair

#define endl '\n'
#define TITLE "B"

#define gc getchar
#define pc putchar
#define length Len

//-----------------------------------------------------

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

const int N = 223;
const int oo = 1000000000;
bool DEBUG = 1;
ll n, m, f[N], k[N], MAX = 0;

struct T
{

};

void Init()
{
    cin >> n >> m;
    if(m == 0 && n == 1) {cout << 1; exit(0);}
    memset(f , 0 , sizeof(f));
    up(i , 1 , m)
        cin >> f[i] >> k[i], MAX = max(MAX , f[i]);
}

bool ok(ll flat)
{
    up(i , 1 , m) {
        bool z = 0;
        if((k[i] - 1) * flat < f[i] && f[i] <= (k[i] * flat)) z = 1;
        if(!z) return false;
    }
    return true;
}

ll Cnt(ll res)
{
    ll ans = n / res;
    if(n > res * ans && res != -1) ans++;
    return ans;
}

void Solve()
{
    ll L = 1, H = 100, res[102], cnt = 0;
    memset(res , -1 , sizeof(res));
    up(i , 1 , 100) {

        if(ok(i))
            res[++cnt] = i;
    }

    ll anw[102], ant = 0;
    bool ok = 1;

    up(i , 1 , cnt) {
        anw[i] = Cnt(res[i]);
        anw[0] = anw[1];
        if(anw[i] != anw[i - 1]) ok = 0;
    }

    if(cnt == 0 || !ok) cout << -1;
    else cout << anw[1];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

  //  freopen(TITLE".INP", "r", stdin);
  //  freopen(TITLE".OUT", "w", stdout);

    int Test = 1;
    //cin >> Test;
    up(i , 1 , Test) {
        Init();
        Solve();
    }
}

/*
/// ***************************** FAST I/O *****************************
inline void read(long long &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

inline void writeln(long long x)
{
     char buffor[21];
     register int i=0;
     int neg=0; if (x<0) {neg=1; x= -x;}
     do{
           buffor[i++]=(x%10)+'0';
           x/=10;
        } while(x);
       i--;
       if (neg) pc('-');
       while(i>=0) pc(buffor[i--]);
       pc('\n');
}
/// ***************************** FAST I/O *****************************
*/


#include <bits/stdc++.h>

//-----------------------------------------------------
/// SOL
///
///
//-----------------------------------------------------

#define up(i , a , b) for(int i = a ; i <= b; ++i)
#define up2(i , a , b , c) for(int i = a ; i <= b; i += c)
#define down(i , a , b) for (int i = a; i >= b; --i)
#define down2(i , a , b , c) for (int i = a; i >= b; i -= c)

#define II pair <int, int>
#define III pair<int, pair<int, int> >

#define pb push_back
#define mp make_pair

#define endl '\n'
#define TITLE "B"

#define gc getchar
#define pc putchar
#define length Len

//-----------------------------------------------------

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

const int N = 223;
const int oo = 1000000000;
bool DEBUG = 1;
ll n, m, f[N], k[N], MAX = 0;

struct T
{

};

void Init()
{
    cin >> n >> m;
    if(m == 0 && n == 1) {cout << 1; exit(0);}
    memset(f , 0 , sizeof(f));
    up(i , 1 , m)
        cin >> f[i] >> k[i], MAX = max(MAX , f[i]);
}

bool ok(ll flat)
{
    up(i , 1 , m) {
        bool z = 0;
        if((k[i] - 1) * flat < f[i] && f[i] <= (k[i] * flat)) z = 1;
        if(!z) return false;
    }
    return true;
}

void Solve()
{
    ll L = 1, H = 100, res = -1, res2 = -1;

    up(i , 1 , MAX) {

        if(ok(i))
            if(res != -1) {cout << -1; exit(0);}
            else res = i;
    }

    ll ans = n / res;
    if(n > res * ans && res != -1) res++;

    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //freopen(TITLE".INP", "r", stdin);
  //  freopen(TITLE".OUT", "w", stdout);

    int Test = 1;
    //cin >> Test;
    up(i , 1 , Test) {
        Init();
        Solve();
    }
}

/*
/// ***************************** FAST I/O *****************************
inline void read(long long &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

inline void writeln(long long x)
{
     char buffor[21];
     register int i=0;
     int neg=0; if (x<0) {neg=1; x= -x;}
     do{
           buffor[i++]=(x%10)+'0';
           x/=10;
        } while(x);
       i--;
       if (neg) pc('-');
       while(i>=0) pc(buffor[i--]);
       pc('\n');
}
/// ***************************** FAST I/O *****************************
*/


//----------------------------------------------------------------------------------------\\

#include    <iostream>
#include    <cmath>
#include    <iomanip>
#include    <cstdio>
#include    <algorithm>
#include    <string>
#include    <vector>
#include    <stack>
#include    <deque>
#include    <queue>
#include    <map>
#define     ll long long
#define     ull unsigned long long
#define     ld long double
#define     prec(k) << fixed << setprecision(k)
#define     maxN 10007
#define     maxM 100007
#define     maxT 1000007
#define     ii pair<int, int>
#define     X first
#define     Y second
//----------------------------------------------------------------------------------------\\

using namespace std;

int n, m, tmp = 0, tmp1 = 0, fl; ii a[107]; bool chk = false;

void nhap()
{
    cin >> n >> m;
    for (int i = 0 ; i < m ; i ++)
    {
        cin >> a[i].Y >> a[i].X;
    }
    sort(a, a + m);
}

void Solve()
{
    for (int i = 0 ; i < m - 1 ; i ++)
    {
        if (a[i].X != a[i + 1].X)
        {
            if (a[i + 1].Y - a[i].Y == 1)
            {
                tmp = a[i].Y;
                tmp1 = i + 1;
                chk = true;
                break;
            }
        }
    }
    if (chk == true)
    {
        fl = tmp / tmp1;
        if (n % fl == 0) cout << n / fl;
        else cout << n / fl + 1;
    }
    else cout << -1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    nhap();
    Solve();
}


#include <bits/stdc++.h>

//-----------------------------------------------------
/// SOL
///
///
//-----------------------------------------------------

#define up(i , a , b) for(int i = a ; i <= b; ++i)
#define up2(i , a , b , c) for(int i = a ; i <= b; i += c)
#define down(i , a , b) for (int i = a; i >= b; --i)
#define down2(i , a , b , c) for (int i = a; i >= b; i -= c)

#define II pair <int, int>
#define III pair<int, pair<int, int> >

#define pb push_back
#define mp make_pair

#define endl '\n'
#define TITLE "B"

#define gc getchar
#define pc putchar
#define length Len

//-----------------------------------------------------

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

const int N = 223;
const int oo = 1000000000;
bool DEBUG = 1;
ll n, m, f[N], k[N], MAX = 0;

struct T
{

};

void Init()
{
    cin >> n >> m;
    memset(f , 0 , sizeof(f));
    up(i , 1 , m)
        cin >> f[i] >> k[i], MAX = max(MAX , f[i]);
}

bool ok(ll flat)
{
    up(i , 1 , m) {
        bool z = 0;
        if((k[i] - 1) * flat < f[i] && f[i] <= (k[i] * flat)) z = 1;
        if(!z) return false;
    }
    return true;
}

void Solve()
{
    ll L = 1, H = 100, res = -1, res2 = -1;

    up(i , 1 , MAX) {

        if(ok(i))
            if(res != -1) {cout << -1; exit(0);}
            else res = i;
    }

    ll ans = n / res;
    if(n > res * ans && res != -1) res++;

    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //freopen(TITLE".INP", "r", stdin);
  //  freopen(TITLE".OUT", "w", stdout);

    int Test = 1;
    //cin >> Test;
    up(i , 1 , Test) {
        Init();
        Solve();
    }
}

/*
/// ***************************** FAST I/O *****************************
inline void read(long long &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

inline void writeln(long long x)
{
     char buffor[21];
     register int i=0;
     int neg=0; if (x<0) {neg=1; x= -x;}
     do{
           buffor[i++]=(x%10)+'0';
           x/=10;
        } while(x);
       i--;
       if (neg) pc('-');
       while(i>=0) pc(buffor[i--]);
       pc('\n');
}
/// ***************************** FAST I/O *****************************
*/


#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define inf 0x3f3f3f3f
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define N 1000007 // 10e6 + 7

int f[N];

set<int>ans;

int main(int argc, char const *argv[]){
	int n, m;
	cin >> n >> m;
	for(int i=0; i<m; i++){
		int a, b;
		cin >> a >> b;
		f[a]=b;
		if(a==n){
			cout << b << endl;
			return 0;
		}
	}
	for(int i=1; i<=120; i++){
		bool flag=true;
		int cc=0, c=1;
		int cand=0;
		for(int j=1; j<=120; j++){
			if(f[j]!=c and f[j])flag=false;
			if(j==n)cand=c;
			cc++;
			if(cc==i){
				cc=0;
				c++;
			}
		}
		if(flag){
			ans.insert(cand);
		}
	}
	if(ans.size()>1 or ans.size()==0){
		cout << -1 << endl;
	}else cout << *ans.begin() << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define inf 0x3f3f3f3f
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define N 1000007 // 10e6 + 7

int f[N];

vector<int>ans;

int main(int argc, char const *argv[]){
	int n, m;
	cin >> n >> m;
	for(int i=0; i<m; i++){
		int a, b;
		cin >> a >> b;
		f[a]=b;
	}
	for(int i=1; i<=100; i++){
		bool flag=true;
		int cc=0, c=1;
		int cand=0;
		for(int j=1; j<=100; j++){
			if(f[j]!=c and f[j])flag=false;
			if(j==n)cand=c;
			cc++;
			if(cc==i){
				cc=0;
				c++;
			}
		}
		if(flag){
			ans.pb(cand);
		}
	}
	if(ans.size()>1 or ans.size()==0){
		cout << -1 << endl;
	}else cout << ans[0] << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define inf 0x3f3f3f3f
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define N 1000007 // 10e6 + 7

int f[N];

vector<int>ans;

int main(int argc, char const *argv[]){
	int n, m;
	cin >> n >> m;
	for(int i=0; i<m; i++){
		int a, b;
		cin >> a >> b;
		f[a]=b;
		if(a==n){
			cout << m << endl;
			return 0;
		}
	}
	for(int i=1; i<=100; i++){
		bool flag=true;
		int cc=0, c=1;
		int cand=0;
		for(int j=1; j<=100; j++){
			if(f[j]!=c and f[j])flag=false;
			if(j==n)cand=c;
			cc++;
			if(cc==i){
				cc=0;
				c++;
			}
		}
		if(flag){
			ans.pb(cand);
		}
	}
	if(ans.size()>1 or ans.size()==0){
		cout << -1 << endl;
	}else cout << ans[0] << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define inf 0x3f3f3f3f
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define N 1000007 // 10e6 + 7

int f[N];

set<int>ans;

int main(int argc, char const *argv[]){
	int n, m;
	cin >> n >> m;
	for(int i=0; i<m; i++){
		int a, b;
		cin >> a >> b;
		f[a]=b;
		if(a==n){
			cout << m << endl;
			return 0;
		}
	}
	for(int i=1; i<=120; i++){
		bool flag=true;
		int cc=0, c=1;
		int cand=0;
		for(int j=1; j<=120; j++){
			if(f[j]!=c and f[j])flag=false;
			if(j==n)cand=c;
			cc++;
			if(cc==i){
				cc=0;
				c++;
			}
		}
		if(flag){
			ans.insert(cand);
		}
	}
	if(ans.size()>1 or ans.size()==0){
		cout << -1 << endl;
	}else cout << *ans.begin() << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define inf 0x3f3f3f3f
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define N 1000007 // 10e6 + 7

int f[N];

vector<int>ans;

int main(int argc, char const *argv[]){
	int n, m;
	cin >> n >> m;
	for(int i=0; i<m; i++){
		int a, b;
		cin >> a >> b;
		f[a]=b;
		if(a==n){
			cout << m << endl;
			return 0;
		}
	}
	for(int i=1; i<=120; i++){
		bool flag=true;
		int cc=0, c=1;
		int cand=0;
		for(int j=1; j<=120; j++){
			if(f[j]!=c and f[j])flag=false;
			if(j==n)cand=c;
			cc++;
			if(cc==i){
				cc=0;
				c++;
			}
		}
		if(flag){
			ans.pb(cand);
		}
	}
	if(ans.size()>1 or ans.size()==0){
		cout << -1 << endl;
	}else cout << ans[0] << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m ;
    cin >> n >> m ;
    vector < pair < double, double > > vc ;
    for (int i = 0 ; i < m ; i++)
    {
        double flat, floor ;
        cin >> flat >> floor;
        vc.push_back({flat,floor});
    }
    sort(vc.begin(),vc.end());
    int num = -1 ;
    for (int i = 1; i <=100 ; i++)
    {
        bool flag = true;
        for (int j = 0 ; j < m ; j++)
        { double res = ceil(vc[j].first/i);
           int x =res;
            if (x!= vc[j].second)
            {
                flag = false ;
                break;
            }
        }
        if (flag)
        {
            int cnt = 0 ;
            int flats= 0;
            while (flats < n )
            {
                cnt++;
                flats+=i;
            }

            if ((n%i)+(n/i)!= cnt)exit(puts("-1"));
            cout << cnt;
            exit(0);
        }
    }

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m ;
    cin >> n >> m ;
    vector < pair < double, double > > vc ;
    for (int i = 0 ; i < m ; i++)
    {
        double flat, floor ;
        cin >> flat >> floor;
        vc.push_back({flat,floor});
    }
    sort(vc.begin(),vc.end());
    int num = -1 ;
    set < int > ans ;
    for (int i = 1; i <=100 ; i++)
    {
        bool flag = true;
        for (int j = 0 ; j < m ; j++)
        { double res = ceil(vc[j].first/i);
           int x =res;
            if (x!= vc[j].second)
            {
                flag = false ;
                break;
            }
        }
        if (flag)
        {
            int cnt = 0 ;
            int flats= 0;
            while (flats < n )
            {
                cnt++;
                flats+=i;
            }
            ans.insert(cnt);
        }
    }
    if (ans.size()==1)
        cout << *ans.begin();
    else if (n==1)
        cout <<1 ;
    else cout << -1;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m ;
    cin >> n >> m ;
    vector < pair < double, double > > vc ;
    for (int i = 0 ; i < m ; i++)
    {
        double flat, floor ;
        cin >> flat >> floor;
        vc.push_back({flat,floor});
    }
    sort(vc.begin(),vc.end());
    int num = -1 ;
    for (int i = 1; i <=100 ; i++)
    {
        bool flag = true;
        for (int j = 0 ; j < m ; j++)
        { double res = ceil(vc[j].first/i);
           int x =res;
            if (x!= vc[j].second)
            {
                flag = false ;
                break;
            }
        }
        if (flag)
        {
            int cnt = 0 ;
            int flats= 0;
            while (flats < n )
            {
                cnt++;
                flats+=i;
            }
            int x = n/i ;
            if (n%i) x++;

            if (x!= cnt)exit(puts("-1"));
            cout << cnt;
            exit(0);
        }
    }

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n , m ;
    cin >> n >> m ;
    vector < pair < int , int > > vc ;
    for (int i = 0 ; i < m ;i++){
        int flat , floor ;
        cin >> flat >> floor;
        vc.push_back({flat,floor});
    }
    sort(vc.begin(),vc.end());
    int num = -1 ;
    for (int i = 0 ; i <m-1 ;i++){
        if (vc[i+1].second-vc[i].second==1 && vc[i+1].first-vc[i].first==1)
                num=vc[i].first/vc[i].second;
        }
    if (num==-1) exit(puts("-1"));
    int cnt = 0 ;
    int flats= 0;
        while (flats < n ){
        cnt++;
        flats+=num;
     }
     cout << cnt;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n , m ;
    cin >> n >> m ;
    vector < pair < int , int > > vc ;
    for (int i = 0 ; i < m ;i++){
        int flat , floor ;
        cin >> flat >> floor;
        vc.push_back({flat,floor});
    }
    sort(vc.begin(),vc.end());
    int num = -1 ;
    for (int i = 0 ; i <m-1 ;i++){
        if (vc[i+1].second-vc[i].second==1 && vc[i+1].first-vc[i].first==1)
                num=vc[i].first/vc[i].second;
        }
    if (num==-1) {
        for (int i = 0 ; i <m;i++){
            if (abs(vc[i].first-n)==1 || (vc[i].first <= m && m  <= vc[i+1].first && (vc[i].second==vc[i+1].second)))
                cout << vc[i].second ,exit(0);

        }
        exit(puts("-1"));
    }
    int cnt = 0 ;
    int flats= 0;
        while (flats < n ){
        cnt++;
        flats+=num;
     }
     cout << cnt;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define N 102
using namespace std;
int n,m;
struct Node{
  int x,y;
}k[N];
int ans,cnt;
int mi=101,mx=0;
int main(){
  cin>>n>>m;
  bool flag=true;
  for(int i=0;i<m;i++){
    cin>>k[i].x>>k[i].y;
    mi=min(mi,k[i].x);
    mx=max(mx,k[i].x);
  }
  if(n==1&&m==0){
    cout<<1<<endl;
    return 0;
  }
  for(int i=1;i<=100;i++){
    bool prime=true;
    for(int j=0;j<m;j++){
      int t=k[j].x%i==0?k[j].x/i:k[j].x/i+1;
      if(t!=k[j].y){
        prime=false;
        break;
      }
    }
    if(prime){
      cnt++;
      int z=n%i==0?n/i:n/i+1;
      if(z==ans){
        cnt--;
      }
      while(flag){
        ans=z;
        flag=false;
      }
    }
  }
  if(cnt==1){
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define N 102
using namespace std;
int n,m;
struct Node{
  int x,y;
}k[N];
int ans,cnt;
int mi=101,mx=0;
int main(){
  cin>>n>>m;
  bool flag=true;
  for(int i=0;i<m;i++){
    cin>>k[i].x>>k[i].y;
    mi=min(mi,k[i].x);
    mx=max(mx,k[i].x);
  }
  for(int i=1;i<=mx;i++){
    bool prime=true;
    for(int j=0;j<m;j++){
      int t=k[j].x%i==0?k[j].x/i:k[j].x/i+1;
      if(t!=k[j].y){
        prime=false;
        break;
      }
    }
    if(prime){
      cnt++;
      int z=n%i==0?n/i:n/i+1;
      if(z==ans){
        cnt--;
      }
      while(flag){
        ans=z;
        flag=false;
      }
    }
  }
  if(cnt==1){
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define N 102
using namespace std;
int n,m;
struct Node{
  int x,y;
}k[N];
int ans,cnt;
int mi=101,mx=0;
int main(){
  cin>>n>>m;
  bool flag=true;
  for(int i=0;i<m;i++){
    cin>>k[i].x>>k[i].y;
  }
  if(n==1&&m==0){
    cout<<1<<endl;
    return 0;
  }
  for(int i=1;i<=100;i++){
    bool prime=true;
    for(int j=0;j<m;j++){
      int t=k[j].x%i==0?k[j].x/i:k[j].x/i+1;
      if(t!=k[j].y){
        prime=false;
        break;
      }
    }
    if(prime){
      cnt++;
      int z=n%i==0?n/i:n/i+1;
      if(z==ans){
        cnt--;
      }
      while(flag){
        ans=z;
        flag=false;
      }
    }
  }
  if(cnt==1){
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define N 102
using namespace std;
int n,m;
struct Node{
  int x,y;
}k[N];
int ans,cnt;
int mi=101,mx=0;
int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>k[i].x>>k[i].y;
    mi=min(mi,k[i].x);
    mx=max(mx,k[i].x);
  }
  for(int i=1;i<=mx;i++){
    bool prime=true;
    for(int j=0;j<m;j++){
      int t=k[j].x%i==0?k[j].x/i:k[j].x/i+1;
      if(t!=k[j].y){
        prime=false;
        break;
      }
    }
    if(prime){
      cnt++;
      ans=i;
    }
  }
  if(cnt==1){
    int z=n%ans==0?n/ans:n/ans+1;
    cout<<z<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define N 102
using namespace std;
int n,m;
struct Node{
  int x,y;
}k[N];
int ans,cnt;
int mi=101,mx=0;
int main(){
  cin>>n>>m;
  bool flag=true;
  for(int i=0;i<m;i++){
    cin>>k[i].x>>k[i].y;
    mi=min(mi,k[i].x);
    mx=max(mx,k[i].x);
  }
  if(n==1&&m==0){
    cout<<1<<endl;
    return 0;
  }
  for(int i=1;i<=mx;i++){
    bool prime=true;
    for(int j=0;j<m;j++){
      int t=k[j].x%i==0?k[j].x/i:k[j].x/i+1;
      if(t!=k[j].y){
        prime=false;
        break;
      }
    }
    if(prime){
      cnt++;
      int z=n%i==0?n/i:n/i+1;
      if(z==ans){
        cnt--;
      }
      while(flag){
        ans=z;
        flag=false;
      }
    }
  }
  if(cnt==1){
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 10005;
int n,m;
struct node{
	int k,f;
	int id;
}a[maxn];

int fr[maxn];

int cmp(node x,node y){
	return x.f<y.f;
}

int solve(int num){
	int level = 0;
	int i = 0;
	while(i <= 1000){
		for(int j = 0; j < num; j++) {
			fr[i++] = level;
		}
		level++;
	}
	//cout<<num<<endl;
	//for(int i = 0; i < n; i++) cout<<fr[i]<<' ';cout<<endl;
	for(int i = 0; i < m; i++){
		//cout<<a[i].k<<' '<<fr[a[i].k]<<' '<<a[i].f<<endl;
		if(fr[a[i].k] != a[i].f) return 0;
	}
	return 1;
}

int main(){
	cin>>n>>m;
	int ans = -1;
	for(int i = 0; i < m; i++){
		cin>>a[i].k>>a[i].f;
		if(a[i].k == n) {
			ans = a[i].f;
		}
		a[i].k--;
		a[i].f--;
	}
	if(ans != -1){
		cout<<ans<<endl;
		return 0;
	}
	int cnt = 0;
	for(int i = 1; i <= 1000; i++){
		if(solve(i)) {
			cnt++;
			if(cnt > 1) break;
			ans = fr[n - 1] + 1;
		}
	}
	if(ans == -1 || cnt > 1) cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}
/*
10 3
6 2
2 1
7 3

8 4
3 1
6 2
5 2
2 1

*/


#include<bits/stdc++.h>
using namespace std;
const int maxn = 10005;
int n,m;
struct node{
	int k,f;
	int id;
}a[maxn];

int fr[maxn];

int cmp(node x,node y){
	return x.f<y.f;
}

int solve(int num){
	for(int i = 0; i < m; i++){
		//cout<<a[i].k<<' '<<a[i].k/num<<' '<<a[i].f<<endl;
		if(a[i].k/num != a[i].f) return 0;
	}
	return 1;
}

int main(){
	cin>>n>>m;
	int ans = -1;
	for(int i = 0; i < m; i++){
		cin>>a[i].k>>a[i].f;
		if(a[i].k == n) {
			ans = a[i].f;
		}
		a[i].k--;
		a[i].f--;
	}
	if(ans != -1){
		cout<<ans<<endl;
		return 0;
	}
	sort(a,a+m,cmp);
	for(int i = 1; i <= 100; i++){
		if(solve(i)) {
			if(ans != -1) {
				cout<<-1<<endl;
				return 0;
			}
			ans = (n-1)/i + 1;
		}
		//break;
	}
	cout<<ans<<endl;
	return 0;
}
/*
10 3
6 2
2 1
7 3

8 4
3 1
6 2
5 2
2 1

*/


#include<bits/stdc++.h>
using namespace std;
const int maxn = 10005;
int n,m;
struct node{
	int k,f;
	int id;
}a[maxn];

int fr[maxn];

int cmp(node x,node y){
	return x.f<y.f;
}

int solve(int num){
	for(int i = 0; i < m; i++){
		//cout<<a[i].k<<' '<<a[i].k/num<<' '<<a[i].f<<endl;
		if((a[i].k-1)/num+1 != a[i].f) return 0;
	}
	return 1;
}

int main(){
	cin>>n>>m;
	int ans = -1, cnt = 0;
	for(int i = 0; i < m; i++){
		cin>>a[i].k>>a[i].f;
	}
	sort(a,a+m,cmp);
	for(int i = 1; i <= 1000; i++){
		if(solve(i)) {
			cnt++;
			if(cnt > 1){
				cout<<-1<<endl;
				return 0;
			}
			ans = (n-1)/i + 1;
		}
		//break;
	}
	cout<<ans<<endl;
	return 0;
}
/*
10 3
6 2
2 1
7 3

8 4
3 1
6 2
5 2
2 1

*/


#include<bits/stdc++.h>
using namespace std;
const int maxn = 10005;
int n,m;
struct node{
	int k,f;
	int id;
}a[maxn];

int fr[maxn];

int cmp(node x,node y){
	return x.f<y.f;
}

int solve(int num){
	int level = 0;
	int i = 0;
	while(i <= 1000){
		for(int j = 0; j < num; j++) {
			fr[i++] = level;
		}
		level++;
	}
	//cout<<num<<endl;
	//for(int i = 0; i < n; i++) cout<<fr[i]<<' ';cout<<endl;
	for(int i = 0; i < m; i++){
		//cout<<a[i].k<<' '<<fr[a[i].k]<<' '<<a[i].f<<endl;
		if(fr[a[i].k] != a[i].f) return 0;
	}
	return 1;
}

int main(){
	cin>>n>>m;
	for(int i = 0; i < m; i++){
		cin>>a[i].k>>a[i].f;
		a[i].k--;
		a[i].f--;
	}
	sort(a, a+m, cmp);
	int ans = -1;
	int cnt = 0;
	for(int i = 1; i <= 1000; i++){
		if(solve(i)) {
			cnt++;
			if(cnt > 1) break;
			ans = fr[n - 1] + 1;
		}
	}
	if(ans == -1 || cnt > 1) cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}
/*
10 3
6 2
2 1
7 3

8 4
3 1
6 2
5 2
2 1

*/


#include<bits/stdc++.h>
using namespace std;
const int maxn = 10005;
int n,m;
struct node{
	int k,f;
	int id;
}a[maxn];

int fr[maxn];

int cmp(node x,node y){
	return x.f<y.f;
}

int solve(int num){
	for(int i = 0; i < m; i++){
		//cout<<a[i].k<<' '<<a[i].k/num<<' '<<a[i].f<<endl;
		if((a[i].k-1)/num+1 != a[i].f) return 0;
	}
	return 1;
}

int main(){
	cin>>n>>m;
	int ans = -1;
	for(int i = 0; i < m; i++){
		cin>>a[i].k>>a[i].f;
	}
	sort(a,a+m,cmp);
	for(int i = 1; i <= 1000; i++){
		if(solve(i)) {
			if(ans != -1) {
				cout<<-1<<endl;
				return 0;
			}
			ans = (n-1)/i + 1;
		}
		//break;
	}
	cout<<ans<<endl;
	return 0;
}
/*
10 3
6 2
2 1
7 3

8 4
3 1
6 2
5 2
2 1

*/


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n,m;
struct node{
	int k,f;
	int id;
}a[maxn];

int fr[maxn];

int cmp(node x,node y){
	return x.f<y.f;
}

int solve(int num){
	int level = 0;
	int i = 0;
	while(i < n){
		for(int j = 0; j < num; j++) {
			fr[i++] = level;
		}
		level++;
	}
	//cout<<num<<endl;
	//for(int i = 0; i < n; i++) cout<<fr[i]<<' ';cout<<endl;
	for(int i = 0; i < m; i++){
		//cout<<a[i].k<<' '<<fr[a[i].k]<<' '<<a[i].f<<endl;
		if(fr[a[i].k] != a[i].f) return 0;
	}
	return 1;
}

int main(){
	cin>>n>>m;
	for(int i = 0; i < m; i++){
		cin>>a[i].k>>a[i].f;
		a[i].k--;
		a[i].f--;
	}
	sort(a, a+m, cmp);
	int ans = -1;
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		if(solve(i)) {
			cnt++;
			if(cnt > 1) break;
			ans = fr[n - 1] + 1;
		}
	}
	if(ans == -1 || cnt > 1) cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}
/*
10 3
6 2
2 1
7 3

8 4
3 1
6 2
5 2
2 1

*/


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n,m;
struct node{
	int k,f;
	int id;
}a[maxn];

int fr[maxn];

int cmp(node x,node y){
	return x.f<y.f;
}

int solve(int num){
	int level = 0;
	int i = 0;
	while(i < n){
		for(int j = 0; j < num; j++) {
			fr[i++] = level;
		}
		level++;
	}
	//cout<<num<<endl;
	//for(int i = 0; i < n; i++) cout<<fr[i]<<' ';cout<<endl;
	for(int i = 0; i < m; i++){
		//cout<<a[i].k<<' '<<fr[a[i].k]<<' '<<a[i].f<<endl;
		if(fr[a[i].k] != a[i].f) return 0;
	}
	return 1;
}

int main(){
	cin>>n>>m;
	for(int i = 0; i < m; i++){
		cin>>a[i].k>>a[i].f;
		a[i].k--;
		a[i].f--;
	}
	sort(a, a+m, cmp);
	int ans = -1;
	int cnt = 0;
	for(int i = 1; i <= m; i++){
		if(solve(i)) {
			cnt++;
			if(cnt > 1) break;
			ans = fr[n - 1] + 1;
		}
	}
	if(ans == -1 || cnt > 1) cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}
/*
10 3
6 2
2 1
7 3

8 4
3 1
6 2
5 2
2 1

*/


#include<bits/stdc++.h>
using namespace std;
const int maxn = 10005;
int n,m;
struct node{
	int k,f;
	int id;
}a[maxn];

int fr[maxn];

int cmp(node x,node y){
	return x.f<y.f;
}

int solve(int num){
	int level = 0;
	int i = 0;
	while(i < n){
		for(int j = 0; j < num; j++) {
			fr[i++] = level;
		}
		level++;
	}
	//cout<<num<<endl;
	//for(int i = 0; i < n; i++) cout<<fr[i]<<' ';cout<<endl;
	for(int i = 0; i < m; i++){
		//cout<<a[i].k<<' '<<fr[a[i].k]<<' '<<a[i].f<<endl;
		if(fr[a[i].k] != a[i].f) return 0;
	}
	return 1;
}

int main(){
	cin>>n>>m;
	for(int i = 0; i < m; i++){
		cin>>a[i].k>>a[i].f;
		a[i].k--;
		a[i].f--;
	}
	sort(a, a+m, cmp);
	int ans = -1;
	int cnt = 0;
	for(int i = 1; i <= 10000; i++){
		if(solve(i)) {
			cnt++;
			if(cnt > 1) break;
			ans = fr[n - 1] + 1;
		}
	}
	if(ans == -1 || cnt > 1) cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}
/*
10 3
6 2
2 1
7 3

8 4
3 1
6 2
5 2
2 1

*/


#include<bits/stdc++.h>
using namespace std;
const int maxn = 10005;
int n,m;
struct node{
	int k,f;
	int id;
}a[maxn];

int fr[maxn];

int cmp(node x,node y){
	return x.f<y.f;
}

int solve(int num){
	for(int i = 0; i < m; i++){
		//cout<<a[i].k<<' '<<a[i].k/num<<' '<<a[i].f<<endl;
		if((a[i].k-1)/num+1 != a[i].f) return 0;
	}
	return 1;
}

int main(){
	cin>>n>>m;
	int ans = 0;
	for(int i = 0; i < m; i++){
		cin>>a[i].k>>a[i].f;
	}
	sort(a,a+m,cmp);
	for(int i = 1; i <= 1000; i++){
		if(solve(i)) {
			if(ans && ans != (n-1)/i+1) {
				cout<<-1<<endl;
				return 0;
			}
			else ans = (n-1)/i + 1;
		}
		//break;
	}
	cout<<ans<<endl;
	return 0;
}
/*
10 3
6 2
2 1
7 3

8 4
3 1
6 2
5 2
2 1

*/


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cout<<#x<<" -> "<<x<<'\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
const ll infll = powl(2, 62)-1;
const ld pi = 4.0*atanl(1.0);
const ll mod = powl(10, 9) + 7;

int32_t main() {//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n, m;
    cin >> n >> m;
    if(m == 0) {
        cout << "-1\n";
        return 0;
    }
    vector<pair<int, int> > arr(m);
    for(auto &p : arr) cin >> p.first >> p.second;
    set<int> floors;
    vector<vector<int> > floorToFlat(101);
    for(auto &p : arr) floorToFlat[p.second].pb(p.first);
    for(int flatsPerFloor = 1; flatsPerFloor <= 100; ++flatsPerFloor) {
        bool possible = true;
        for(int i = 1; i <= 100; ++i) {
            for(auto &f : floorToFlat[i]) {
                if(ceil(f/(double)flatsPerFloor) != i) {
                    possible = false;
                    break;
                }
            }
            if(!possible) break;
        }
        if(possible) {
            //cout << flatsPerFloor<< " is a possible value for flats per floor\n";
            floors.insert(ceil(n/(double)flatsPerFloor));
        }
    }
    //for(int f : floors) cout << f << ' ';cout << "\n\n";
    if(floors.size() != 1) {
        cout << "-1\n";
        return 0;
    }
    cout << *floors.begin() << '\n';
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cout<<#x<<" -> "<<x<<'\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
const ll infll = powl(2, 62)-1;
const ld pi = 4.0*atanl(1.0);
const ll mod = powl(10, 9) + 7;

int32_t main() {//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > arr(m);
    for(auto &p : arr) cin >> p.first >> p.second;
    set<int> floors;
    vector<vector<int> > floorToFlat(101);
    for(auto &p : arr) floorToFlat[p.second].pb(p.first);
    for(int lower = 0; lower <= 100; ++lower) {
        bool possible = true;
        for(int i = 1; i <= 100; ++i) {
            for(auto &p : floorToFlat[i]) {
                if(lower + i*m - m <= p && p < lower + i*m) {

                } else {
                    possible = false;
                    break;
                }
            }
            if(!possible) break;
        }
        if(possible) {
            floors.insert(n/m + lower);
        }
    }
    if(floors.size() != 1) {
        cout << "-1\n";
        return 0;
    }
    cout << *floors.begin() << '\n';
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cout<<#x<<" -> "<<x<<'\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
const ll infll = powl(2, 62)-1;
const ld pi = 4.0*atanl(1.0);
const ll mod = powl(10, 9) + 7;

int32_t main() {//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > arr(m);
    for(auto &p : arr) cin >> p.first >> p.second;
    set<int> floors;
    vector<vector<int> > floorToFlat(101);
    for(auto &p : arr) floorToFlat[p.second].pb(p.first);
    for(int flatsPerFloor = 1; flatsPerFloor <= 10000; ++flatsPerFloor) {
        bool possible = true;
        for(int i = 1; i <= 100; ++i) {
            for(auto &f : floorToFlat[i]) {
                if(ceil(f/(double)flatsPerFloor) != i) {
                    possible = false;
                    break;
                }
            }
            if(!possible) break;
        }
        if(possible) {
            //cout << flatsPerFloor<< " is a possible value for flats per floor\n";
            floors.insert(ceil(n/(double)flatsPerFloor));
        }
    }
    //for(int f : floors) cout << f << ' ';cout << "\n\n";
    if(floors.size() != 1) {
        cout << "-1\n";
        return 0;
    }
    cout << *floors.begin() << '\n';
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cout<<#x<<" -> "<<x<<'\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
const ll infll = powl(2, 62)-1;
const ld pi = 4.0*atanl(1.0);
const ll mod = powl(10, 9) + 7;

int32_t main() {//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > arr(m);
    for(auto &p : arr) cin >> p.first >> p.second;
    set<int> floors;
    vector<vector<int> > floorToFlat(101);
    for(auto &p : arr) floorToFlat[p.second].pb(p.first);
    for(int lower = 0; lower <= 100; ++lower) {
        bool possible = true;
        for(int i = 1; i <= 100; ++i) {
            for(auto &p : floorToFlat[i]) {
                if(lower + i*m - m <= p && p < lower + i*m) {

                } else {
                    possible = false;
                    break;
                }
            }
            if(!possible) break;
        }
        if(possible) {
            floors.insert((n-1)/m + lower);
        }
    }
    if(floors.size() != 1) {
        cout << "-1\n";
        return 0;
    }
    cout << *floors.begin() << '\n';
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cout<<#x<<" -> "<<x<<'\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
const ll infll = powl(2, 62)-1;
const ld pi = 4.0*atanl(1.0);
const ll mod = powl(10, 9) + 7;

int32_t main() {//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n, m;
    cin >> n >> m;
    if(m == 0) {
        cout << "-1\n";
        return 0;
    }
    vector<pair<int, int> > arr(m);
    for(auto &p : arr) cin >> p.first >> p.second;
    set<int> floors;
    vector<vector<int> > floorToFlat(101);
    for(auto &p : arr) floorToFlat[p.second].pb(p.first);
    for(int lower = 0; lower <= 100; ++lower) {
        bool possible = true;
        for(int i = 1; i <= 100; ++i) {
            for(auto &p : floorToFlat[i]) {
                if(lower + i*m - m <= p && p < lower + i*m) {

                } else {
                    possible = false;
                    break;
                }
            }
            if(!possible) break;
        }
        if(possible) {
            floors.insert((n-1)/m + lower);
        }
    }
    if(floors.size() != 1) {
        cout << "-1\n";
        return 0;
    }
    cout << *floors.begin() << '\n';
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cout<<#x<<" -> "<<x<<'\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
const ll infll = powl(2, 62)-1;
const ld pi = 4.0*atanl(1.0);
const ll mod = powl(10, 9) + 7;

int32_t main() {//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n, m;
    cin >> n >> m;
    if(m == 0) {
        cout << "-1\n";
        return 0;
    }
    vector<pair<int, int> > arr(m);
    for(auto &p : arr) cin >> p.first >> p.second;
    set<int> floors;
    vector<vector<int> > floorToFlat(101);
    for(auto &p : arr) floorToFlat[p.second].pb(p.first);
    for(int flatsPerFloor = 1; flatsPerFloor <= 10000; ++flatsPerFloor) {
        bool possible = true;
        for(int i = 1; i <= 100; ++i) {
            for(auto &f : floorToFlat[i]) {
                if(ceil(f/(double)flatsPerFloor) != i) {
                    possible = false;
                    break;
                }
            }
            if(!possible) break;
        }
        if(possible) {
            //cout << flatsPerFloor<< " is a possible value for flats per floor\n";
            floors.insert(ceil(n/(double)flatsPerFloor));
        }
    }
    //for(int f : floors) cout << f << ' ';cout << "\n\n";
    if(floors.size() != 1) {
        cout << "-1\n";
        return 0;
    }
    cout << *floors.begin() << '\n';
    return 0;
}


#include<bits/stdc++.h>
#include <complex>

#define Write freopen("out.txt","w",stdout)
#define Read freopen("in.txt","r",stdin)

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define m_p make_pair
#define ll long long

#define lim 10000000
#define mod 100007
#define dist(ax,ay,bx,by)   ((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
/*Geometry*/
#define X real()
#define Y imag()
/*Geometry*/

using namespace std;

typedef complex < ll > cmp;
//char str[100000];
//map<char,int>mp;
//map<char,int>::iterator it;
//int main()
//{
//    scanf("%s",&str);
//    ll ln=strlen(str);
//    bool flag=false;
//    bool check=false;
//    for(ll i=0; i<ln-2; i++)
//    {
//        if(str[i]!='a'&&str[i]!='e'&&str[i]!='i'&&str[i]!='o'&&str[i]!='u'
//                &&str[i+1]!='a'&&str[i+1]!='e'&&str[i+1]!='i'&&str[i+1]!='o'&&str[i+1]!='u'
//                &&str[i+2]!='a'&&str[i+2]!='e'&&str[i+2]!='i'&&str[i+2]!='o'&&str[i+2]!='u'
//          )
//        {
//            if(str[i]==str[i+1]&&str[i]==str[i+2])
//            {
//                check=true;
//            }
//            else flag=true;
//        }
//    }
//    if(check&&flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//            if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//    }
//    }
//    else if(flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//             if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//        }
//
//
//    }
//    else
//    {
//        printf("%s\n",str);
//    }
//
//}
int arr[1000];
int check[1000];
set < int > s;
set < int > ::iterator it;
int main()
{
    int a,b;
    sii(a,b);
    for(int i=0;i<b;i++){
        int x,y;
        sii(x,y);
        arr[x]=y;
        check[i]=x;
    }
    int cnt=0,ans;
    int flag=true;
    for(int i=1;i<=100;i++)
    {    flag=true;
        for(int j=0;j<b;j++)
        {
            int ase=arr[check[j]];

            int lagbe=(check[j]/i);
            if(check[j]%i!=0) lagbe++;

          if(ase!=lagbe) flag=false;
        }
        if(flag) {
                ///cout<<i<<endl;
                int p=a/i;
                if(a%i!=0) p++;
                //cout<<p<<endl;
                s.insert(p);
        }

    }
    if(s.size()==1)
    {
        it=s.begin();
        cout<<*it<<endl;
    }
    else{
        cout<<"-1"<<endl;
    }

}


#include<bits/stdc++.h>
#include <complex>

#define Write freopen("out.txt","w",stdout)
#define Read freopen("in.txt","r",stdin)

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define m_p make_pair
#define ll long long

#define lim 10000000
#define mod 100007
#define dist(ax,ay,bx,by)   ((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
/*Geometry*/
#define X real()
#define Y imag()
/*Geometry*/

using namespace std;

typedef complex < ll > cmp;
//char str[100000];
//map<char,int>mp;
//map<char,int>::iterator it;
//int main()
//{
//    scanf("%s",&str);
//    ll ln=strlen(str);
//    bool flag=false;
//    bool check=false;
//    for(ll i=0; i<ln-2; i++)
//    {
//        if(str[i]!='a'&&str[i]!='e'&&str[i]!='i'&&str[i]!='o'&&str[i]!='u'
//                &&str[i+1]!='a'&&str[i+1]!='e'&&str[i+1]!='i'&&str[i+1]!='o'&&str[i+1]!='u'
//                &&str[i+2]!='a'&&str[i+2]!='e'&&str[i+2]!='i'&&str[i+2]!='o'&&str[i+2]!='u'
//          )
//        {
//            if(str[i]==str[i+1]&&str[i]==str[i+2])
//            {
//                check=true;
//            }
//            else flag=true;
//        }
//    }
//    if(check&&flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//            if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//    }
//    }
//    else if(flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//             if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//        }
//
//
//    }
//    else
//    {
//        printf("%s\n",str);
//    }
//
//}
int arr[1000];
int check[1000];
int main()
{
    int a,b;
    sii(a,b);
    for(int i=0; i<b; i++)
    {
        int x,y;
        sii(x,y);
        arr[x]=y;
        check[i]=x;
    }
    int cnt=0,ans;
    int flag=true;
    for(int i=1; i<=100; i++)
    {
        flag=true;
        for(int j=0; j<b; j++)
        {
            int ase=arr[check[j]];
            int lagbe=(check[j]/i);
            int p=lagbe+1;
            if(check[j]%i!=0&&check[j]<p*i)
            {
                lagbe++;
            }

            if(ase!=lagbe) flag=false;
        }
        if(flag)
        {
            cnt++;
            ans=i;
        }

    }
    if(cnt==1)
    {
        int p=a/ans;
        if(a%ans!=0) p++;
        cout<<p<<endl;
    }
    else
    {
        cout<<"-1"<<endl;
    }

}