#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 9;
struct node {
  int x, y, z;
} a[maxn];
int b[maxn];
int n, m;
priority_queue<node> que;
bool operator<(node a1, node a2) {
  if (a1.y != a2.y)
    return a1.y > a2.y;
  else
    return a1.x > a2.x;
}
bool cmp(node a1, node a2) {
  if (a1.x != a2.x)
    return a1.x < a2.x;
  else
    return a1.z < a2.z;
}
void work() {
  int i, j, k;
  node q;
  j = 0;
  k = 0;
  for (i = 1; i <= n; i++) {
    while (!que.empty()) {
      q = que.top();
      if (q.y < i)
        que.pop();
      else
        break;
    }
    while (j < m && a[j].x <= i) {
      que.push(a[j]);
      j++;
    }
    if (!que.empty()) {
      q = que.top();
      b[k++] = q.z;
      que.pop();
    }
  }
  printf("%d\n", k);
  for (i = 0; i < k - 1; i++) printf("%d ", b[i]);
  printf("%d\n", b[k - 1]);
}
void init() {
  int i;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    a[i].z = i + 1;
    scanf("%d%d", &a[i].y, &a[i].x);
    a[i].x = n - a[i].x + 1;
  }
  sort(a, a + m, cmp);
}
int main() {
  init();
  work();
  return 0;
}
