#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > A[100000];
vector<pair<int, int> > B[100000];
vector<int> R;
set<pair<int, int> > S;
int F1(int x, int y) { return y; }
int F2(int x, int y) { return n - x - 1; }
int main() {
  cin >> n >> m;
  for (int(i) = (0); (i) < (m); ++(i)) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    A[v].push_back(make_pair(u, i));
    B[u].push_back(make_pair(v, i));
  }
  int p = n - 1;
  for (int i = n - 1; i >= 0; i--) {
    for (int(j) = (0); (j) < (A[i].size()); ++(j)) S.insert(A[i][j]);
    if (!S.empty()) {
      pair<int, int> t;
      t = *S.begin();
      R.push_back(t.second);
      S.erase(S.begin());
    }
    int t = n - i - 1;
    for (int(j) = (0); (j) < (B[t].size()); ++(j))
      if (S.find(make_pair(t, B[t][j].second)) != S.end())
        S.erase(S.find(make_pair(t, B[t][j].second)));
  }
  cout << R.size() << endl;
  for (int(i) = (0); (i) < (R.size()); ++(i)) cout << R[i] + 1 << ' ';
  return 0;
}
