#include <stdio.h>
#include <stdbool.h>
int main() {
    int n, m;
    if (scanf("%d %d", &n, &m) != EOF) {
        int t, x, i;
        bool box[n + 1];
        for(i = 1; i <= n; i++) {
            box[i] = false;
        }
        int count = 0;
        int opnums = 0;
        for(i = 0; i < m; i++) {
            if(scanf("%d%d", &t, &x) != EOF) {
                opnums++;
                switch (t) {
                    case 1:
                        if(box[x] == false) {
                            box[x] = true;
                            count++;
                        }
                        break;
                    case 2:
                        if(box[x]) {
                            printf("%d\n", opnums);
                            return 0;
                        }
                        for(int j = 1; j < x; j++) {
                            box[j] = true;
                        }
                        for(int j = x + 1; j <= n; j++) {
                            box[j] = true;
                        }
                        count = n - 1;
                        break;
                }
                if(count == n) {
                    printf("%d\n", opnums);
                    return 0;
                }
            } else printf("error2\n");
        }
    } else printf("error\n");
    printf("-1\n");
    return 0;
}