#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7, dp[200010], rm[200010], mps[200010], mpt[200010],
          vis[200010], bit[200010], cnt;
vector<pair<long long, long long> > v;
void upd(long long i, long long val) {
  for (; i <= cnt; i += i & -i) bit[i] = (bit[i] + val) % mod;
  return;
}
long long qry(long long i) {
  long long ret = 0;
  for (; i > 0; i -= i & -i) ret = (ret + bit[i]) % mod;
  return ret;
}
int main() {
  long long n, m, i, x, y;
  cin >> n >> m;
  if (m == 0) {
    cout << 0 << "\n";
    return 0;
  }
  for (i = 1; i <= m; i++) {
    cin >> x >> y;
    v.push_back(make_pair(x, i));
    v.push_back(make_pair(y, -i));
  }
  sort(v.begin(), v.end());
  cnt = 1;
  mps[v[0].second] = cnt;
  rm[cnt] = v[0].first;
  for (i = 1; i < (int)(v.size()); i++) {
    if (v[i].first != v[i - 1].first) cnt++;
    if (v[i].second > 0)
      mps[v[i].second] = cnt;
    else
      mpt[-v[i].second] = cnt;
    rm[cnt] = v[i].first;
  }
  if (rm[1] != 0 || rm[cnt] != n) {
    cout << 0 << "\n";
    return 0;
  }
  upd(1, 1);
  v.clear();
  for (i = 1; i <= m; i++) v.push_back(make_pair(mpt[i], mps[i]));
  sort(v.begin(), v.end());
  for (i = 0; i < m; i++)
    upd(v[i].first,
        (qry(v[i].first - 1) - qry(v[i].second - 1) + 2 * mod) % mod);
  cout << (qry(cnt) - qry(cnt - 1) + 2 * mod) % mod << "\n";
  return 0;
}
