#include <bits/stdc++.h>
using namespace std;
struct rec {
  int l, r;
} a[200000];
int n, m;
vector<int> in[200000];
vector<int> out[200000];
vector<int> res;
set<pair<int, int> > S;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int &l = a[i].l, &r = a[i].r;
    scanf("%d%d", &l, &r);
    l = n - l + 1;
    in[l].push_back(i);
    out[r].push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < in[i].size(); ++j) {
      int k = in[i][j];
      S.insert(make_pair(a[k].r, k));
    }
    if (!S.empty()) {
      typeof(S.begin()) it = S.begin();
      res.push_back((*it).second);
      S.erase(it);
    }
    for (int j = 0; j < out[i].size(); ++j) {
      int k = out[i][j];
      typeof(S.begin()) it = S.find(make_pair(a[k].r, k));
      if (it != S.end()) S.erase(it);
    }
  }
  printf("%d\n", res.size());
  for (int i = 0; i < res.size(); ++i) {
    if (i > 0) putchar(' ');
    printf("%d", res[i] + 1);
  }
  puts("");
  return 0;
}
