#include <bits/stdc++.h>
std::vector<long long> bit;
long long sum(int i) {
  long long s = 0;
  while (i > 0) {
    s += bit[i];
    s %= 1000000007;
    i -= i & -i;
  }
  return s;
}
void add(int i, long long x, int n) {
  while (i <= n) {
    bit[i] += x;
    bit[i] %= 1000000007;
    i += i & -i;
  }
}
struct Comp {
  bool operator()(const std::pair<int, int>& lhs,
                  const std::pair<int, int>& rhs) const {
    return lhs.second < rhs.second ||
           (lhs.second == rhs.second && lhs.first < rhs.first);
  }
};
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  std::map<int, int> map;
  std::vector<std::pair<int, int> > v;
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    map[a] = 0;
    map[b] = 0;
    v.push_back(std::make_pair(a, b));
  }
  map[0] = 0;
  map[n] = 0;
  int t = 0;
  for (std::map<int, int>::iterator i = map.begin(); i != map.end(); ++i) {
    (*i).second = ++t;
  }
  for (int i = 0; i < m; ++i) {
    v[i].first = map[v[i].first];
    v[i].second = map[v[i].second];
  }
  std::sort(v.begin(), v.end(), Comp());
  bit = std::vector<long long>(t + 1);
  add(1, 1, t);
  for (int i = 0; i < m; ++i) {
    long long x = sum(v[i].second - 1) - sum(v[i].first - 1);
    x %= 1000000007;
    add(v[i].second, x, t);
  }
  std::cout << (sum(t) - sum(t - 1) + 1000000007) % 1000000007 << std::endl;
}
