#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 18;
long long a[MAXN + 10];
int n, m;
void Set(int i, long long x) {
  i++;
  while (i <= MAXN) {
    a[i] += x;
    a[i] %= 1000000007;
    i += i & -i;
  }
}
long long Get(int i) {
  i++;
  if (i < 1) return 0;
  long long ans = 0;
  while (i > 0) {
    ans += a[i];
    ans %= 1000000007;
    i -= i & -i;
  }
  return ans % 1000000007;
}
long long Get(int x, int y) {
  return (Get(y) - Get(x - 1) + 1000000007) % 1000000007;
}
vector<pair<int, pair<bool, int> > > tmp;
vector<int> v[200005];
int ts[200005];
int main() {
  bool flag = false;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int s, t;
    scanf("%d%d", &s, &t);
    if (s == 0) flag = true;
    tmp.push_back(make_pair(s, make_pair(true, i)));
    tmp.push_back(make_pair(t, make_pair(false, i)));
  }
  if (!flag) {
    cout << 0 << endl;
    return 0;
  }
  sort(tmp.begin(), tmp.end());
  int id = 0, last_pos = -1000000007;
  for (int i = 0; i < tmp.size(); i++) {
    int pos = tmp[i].first;
    bool type = tmp[i].second.first;
    int rawid = tmp[i].second.second;
    if (pos != last_pos) {
      last_pos = pos;
      id++;
    }
    if (tmp[i].second.first) {
      ts[rawid] = id;
    } else {
      v[id].push_back(rawid);
    }
  }
  if (last_pos != n) {
    cout << 0 << endl;
    return 0;
  }
  Set(1, 1ll);
  for (int i = 1; i <= id; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      int start = ts[v[i][j]];
      Set(i, Get(start, i - 1) % 1000000007);
    }
  }
  cout << Get(id, id) % 1000000007 << endl;
  return 0;
}
