#include <bits/stdc++.h>
using namespace std;
int dp[100000];
vector<pair<int, int> > tees;
int rec(int i) {
  if (dp[i] != -1) {
    return dp[i];
  }
  if (i == 0) {
    if (tees[i].second == 0) {
      dp[i] = 1;
    } else {
      dp[i] = 0;
    }
    return dp[i];
  }
  int lw;
  lw =
      int(lower_bound(tees.begin(), tees.end(), make_pair(tees[i].second, -1)) -
          tees.begin());
  int hw;
  hw = int(lower_bound(tees.begin(), tees.end(), make_pair(tees[i].first, -1)) -
           tees.begin());
  if (hw == lw) {
    dp[i] = rec(i - 1);
    if (tees[i].second == 0) {
      dp[i] = (dp[i] + 1) % 1000000007;
    }
    return dp[i];
  }
  lw--;
  hw--;
  int aa;
  if (lw < 0) {
    aa = 0;
  } else {
    aa = rec(lw);
  }
  int bb;
  if (hw < 0) {
    bb = 0;
  } else {
    bb = rec(hw);
  }
  int tot = 0;
  if (tees[i].second == 0) {
    tot = 1;
  }
  tot = (bb - aa + 1000000007 + tot) % 1000000007;
  dp[i] = (tot + rec(i - 1)) % 1000000007;
  return dp[i];
}
int ded(int i) {
  if (i == 0) {
    return rec(i);
  }
  return (rec(i) - rec(i - 1) + 1000000007) % 1000000007;
}
int main() {
  int n, m;
  cin >> n >> m;
  int s, t;
  for (int i = 0; i < 100000; i++) {
    dp[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    cin >> s >> t;
    tees.push_back(make_pair(t, s));
  }
  sort(tees.begin(), tees.end());
  int total = 0;
  for (int i = 0; i < m; i++) {
    if (tees[i].first == n) {
      total = (total + ded(i)) % 1000000007;
    }
  }
  cout << total << endl;
  return 0;
}
