#include <bits/stdc++.h>
using namespace std;
const int MAXM = 100010;
int n, m;
int res[MAXM];
struct In {
  friend bool operator<(In n1, In n2) { return n1.c > n2.c; }
  int r;
  int c;
  int inx;
} p;
struct Node {
  int r;
  int c;
  int inx;
} s[MAXM];
priority_queue<In> pq;
bool cmp(Node a, Node b) {
  if (a.r != b.r)
    return a.r < b.r;
  else
    return a.c < b.c;
}
int main() {
  scanf("%d%d", &n, &m);
  int i, j, tot = 0;
  for (i = 0; i < m; i++) {
    scanf("%d%d", &s[i].r, &s[i].c);
    s[i].r = n + 1 - s[i].r;
    s[i].inx = i + 1;
  }
  sort(s, s + m, cmp);
  j = 0;
  for (i = 1; i <= n; i++) {
    while (j < m && s[j].r == i) {
      p.r = s[j].r;
      p.c = s[j].c;
      p.inx = s[j].inx;
      pq.push(p);
      j++;
    }
    while (!pq.empty() && pq.top().c < i) pq.pop();
    if (!pq.empty()) {
      res[tot++] = pq.top().inx;
      pq.pop();
    }
  }
  printf("%d\n", tot);
  for (i = 0; i < tot; i++) printf("%d%c", res[i], i == tot - 1 ? '\n' : ' ');
  return 0;
}
