#include <bits/stdc++.h>
using namespace std;
struct sport_t {
  int r, c, num;
};
bool cmp(const sport_t &o, const sport_t &p) { return o.r > p.r; }
int n, m;
vector<sport_t> sport;
vector<bool> isok;
priority_queue<pair<int, int> > kol;
int main() {
  scanf("%d%d", &n, &m);
  sport.resize(m);
  isok.resize(m);
  fill(isok.begin(), isok.end(), false);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &sport[i].r, &sport[i].c);
    sport[i].num = i;
  }
  sort(sport.begin(), sport.end(), cmp);
  int pos = 0, ret = 0;
  for (int i = n; i > 0; --i) {
    while (pos < m && sport[pos].r == i) {
      kol.push(make_pair(-sport[pos].c, sport[pos].num));
      pos++;
    }
    while (!kol.empty() && -kol.top().first <= n - i) {
      kol.pop();
    }
    if (!kol.empty()) {
      isok[kol.top().second] = true;
      kol.pop();
      ret++;
    }
  }
  printf("%d\n", ret);
  for (int i = 0; i < m; ++i) {
    if (isok[i]) {
      printf("%d ", i + 1);
    }
  }
  printf("\n");
  return 0;
}
