#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
template <typename T>
class BIT {
 private:
  const long long n;
  vector<T> bit;

 public:
  BIT(long long size) : n(size + 1), bit(n, 0) {}
  BIT(const vector<T> &v) : n((long long)v.size() + 1), bit(n, 0) {
    for (long long i = 0; i < n - 1; i++) add(i, v[i]);
  }
  T sum(long long i) {
    i++;
    T s = 0;
    while (i > 0) {
      s += bit[i], i -= i & -i;
    }
    return s;
  }
  void add(long long i, T x) {
    i++;
    while (i < n) bit[i] += x, i += i & -i;
  }
  void print() {
    for (long long i = 0; i < n - 1; i++)
      cout << sum(i) - sum(i - 1) << (i != n - 2 ? " " : "\n");
  }
  void print_sum() {
    for (long long i = 0; i < n; i++)
      cout << sum(i - 1) << (i != n - 1 ? " " : "\n");
  }
};
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout << fixed << setprecision(15);
  ;
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> lr(k);
  for (long long i = 0, i_len = (long long)(k); i < i_len; i++)
    cin >> lr[i].first >> lr[i].second;
  sort(lr.begin(), lr.end());
  BIT<long long> dp(n + 2);
  dp.add(1, 1);
  for (long long i = 1; i <= n; i++) {
    long long num = (i == 1 ? dp.sum(i) : dp.sum(i) - dp.sum(1));
    for (long long j = 0; j < k; j++) {
      long long l = min(i + lr[j].first, n + 1);
      long long r = min(i + lr[j].second + 1, n + 1);
      dp.add(l, num);
      dp.add(r, -num);
    }
  }
  cout << dp.sum(n) - dp.sum(1) << "\n";
  return 0;
}
