#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<pair<int, int>, int> > e;
bool visited[100100];
priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,
               greater<pair<pair<int, int>, int> > >
    heap;
vector<int> ans;
bool cmp(pair<pair<int, int>, int> u, pair<pair<int, int>, int> v) {
  if (u.first.second != v.first.second) return u.first.second > v.first.second;
  return u.first.first < v.first.first;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int r, c;
    scanf("%d%d", &r, &c);
    e.push_back(make_pair(make_pair(r, c), i));
  }
  sort(e.begin(), e.end(), cmp);
  int last = 0;
  for (int i = 1; i <= n; i++) {
    int r, c, ind;
    while (last < m && e[last].first.second == n + 1 - i) heap.push(e[last++]);
    r = i;
    c = i;
    while (!heap.empty() && heap.top().first.first < r) heap.pop();
    if (!heap.empty()) {
      ans.push_back(heap.top().second);
      heap.pop();
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i] + 1);
}
