#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
clock_t clk = clock();
long long int i, j;
void solve(void);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t = 1;
  while (t--) solve();
  return 0;
}
vector<pair<long long int, long long int> > v;
vector<long long int> tem;
set<long long int> temp;
bool func(pair<long long int, long long int> p1,
          pair<long long int, long long int> p2) {
  if (p1.first != p2.first)
    return p1.first < p2.first;
  else
    return p1.second > p2.second;
}
map<long long int, long long int> rel;
map<long long int, bool> vis;
long long int relation[100001];
void solve() {
  long long int n, m;
  cin >> n >> m;
  temp.insert(0);
  for (i = 1; i <= m; ++i) {
    long long int u, y;
    cin >> u >> y;
    v.push_back({y, u});
    temp.insert(y);
  }
  for (auto it = temp.begin(); it != temp.end(); ++it) tem.push_back(*it);
  sort(v.begin(), v.end(), func);
  sort(tem.begin(), tem.end());
  int cnt = 1;
  for (i = 0; i <= (int)tem.size() - 1; ++i)
    if (rel[tem[i]] == 0) {
      rel[tem[i]] = cnt;
      ++cnt;
    }
  relation[1] = 1;
  for (i = 0; i <= (int)v.size() - 1; ++i) {
    long long int idx = v[i].first;
    if (vis[idx] == 1) continue;
    long long int val = 0;
    int k;
    for (k = i; k < (int)v.size() && v[k].first == idx; ++k) {
      int pos1 = lower_bound(tem.begin(), tem.end(), v[k].second) - tem.begin();
      int pos2 =
          upper_bound(tem.begin(), tem.end(), v[k].first - 1) - tem.begin();
      --pos2;
      pos2 = rel[tem[pos2]];
      pos1 = rel[tem[pos1]];
      val = (val +
             (relation[pos2] - relation[pos1 - 1] + 1000000007) % 1000000007) %
            1000000007;
    }
    relation[rel[idx]] = (relation[rel[idx] - 1] + val) % 1000000007;
    vis[idx] = 1;
  }
  cout << (relation[rel[n]] - relation[rel[n] - 1] + 1000000007) % 1000000007
       << "\n";
}
