#include <bits/stdc++.h>
using namespace std;
struct Node {
  bool out;
  int other;
  int now;
  Node() { out = other = now = 0; }
  Node(int n, int oth, bool b) {
    now = n;
    other = oth;
    out = b;
  }
  bool operator<(Node B) const { return now < B.now; }
};
vector<Node> v;
map<int, int> Index;
long long dp[200005];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int start, end;
    cin >> start >> end;
    v.push_back(Node(start, end, true));
    v.push_back(Node(end, start, false));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) Index[v[i].now] = i;
  long long ans = 0;
  int i = v.size() - 1;
  if (v.size() == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (v[v.size() - 1].out || v[v.size() - 1].now != n || !v[0].out ||
      v[0].now != 0) {
    cout << 0 << endl;
    return 0;
  }
  while (i >= 0) {
    if (i == v.size() - 1)
      dp[i] = 1;
    else
      dp[i] = ans;
    int V = v[i].now;
    int ii = i;
    while (i >= 0 && v[i].now == V) {
      dp[i] = dp[ii];
      if (v[i].out) {
        ans = (1000000007 + ans - dp[Index[v[i].other]]) % 1000000007;
      } else {
        ans = (ans + dp[i]) % 1000000007;
      }
      i--;
    }
  }
  cout << dp[0] << endl;
  return 0;
}
