#include <bits/stdc++.h>
using namespace std;
struct P {
  int x, y;
  int id;
  const bool operator<(const P& b) const {
    if (x != b.x) return x < b.x;
    return y > b.y;
  }
} p[100005];
int main() {
  int n, m;
  while (cin >> n >> m) {
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      p[i].y = x;
      p[i].x = n + 1 - y;
      p[i].id = i + 1;
    }
    sort(p, p + m);
    priority_queue<pair<int, int> > pr;
    int ans = 0;
    int now = 1;
    vector<int> v;
    int it = 0;
    while (now <= n) {
      while (it < m && p[it].x <= now) {
        pr.push(make_pair(-p[it].y, it));
        it++;
      }
      while (!pr.empty() && (-pr.top().first) < now) pr.pop();
      if (!pr.empty()) {
        ans++;
        v.push_back(p[pr.top().second].id);
        pr.pop();
      }
      now++;
    }
    cout << ans << endl;
    for (int i = 0; i < v.size(); i++) cout << v[i] << ' ';
    cout << endl;
  }
  return 0;
}
