#include <bits/stdc++.h>
using namespace std;
const int sportsmanMax = 100010;
int Degree, SpoNum;
struct sportsmanType {
  int r, c, id;
  void Get(int ID) {
    cin >> r >> c;
    id = ID;
  }
  void Print() { printf("%d %d\n", r, c); }
  friend bool operator<(const sportsmanType s1, const sportsmanType s2) {
    return (s1.c > s2.c);
  }
} sportsman[sportsmanMax], choose[sportsmanMax];
bool cmp(const sportsmanType s1, const sportsmanType s2) {
  return (s1.r > s2.r);
}
int main() {
  while (cin >> Degree >> SpoNum) {
    for (int i = 0; i < SpoNum; i++) sportsman[i].Get(i + 1);
    sort(sportsman, sportsman + SpoNum, cmp);
    int ans = 0;
    int j = 0;
    priority_queue<sportsmanType> p;
    for (int i = Degree; i >= 1; i--) {
      while (j < SpoNum && sportsman[j].r == i) p.push(sportsman[j++]);
      while (!p.empty() && p.top().c < (Degree + 1 - i)) {
        p.pop();
      }
      if (!p.empty()) {
        choose[ans++] = p.top();
        p.pop();
      }
    }
    cout << ans << endl;
    for (int i = 0; i < ans - 1; i++) cout << choose[i].id << ' ';
    if (ans) cout << choose[ans - 1].id << endl;
  }
  return 0;
}
