#include <bits/stdc++.h>
using namespace std;
long long totalWays(long long n, long long m, long long dp[], long long b[]) {
  if (n < 0) return 0;
  if (n == 0) return 1;
  if (dp[n] == 0) {
    for (int i = 0; i < m; i++) dp[n] += totalWays((n - 1 - b[i]), m, dp, b);
  }
  return dp[n];
}
int main() {
  long long n, k;
  cin >> n >> k;
  long long a[n], b[100] = {0}, q = 0, j, i, l1, r1;
  for (i = 0; i < n; i++) {
    a[i] = i + 1;
  }
  for (i = 1; i <= k; i++) {
    cin >> l1 >> r1;
    for (j = l1 - 1; j <= r1 - 1; j++) {
      b[q] = a[j];
      q++;
    }
  }
  long long dp[200001] = {0};
  cout << totalWays(n - 1, q, dp, b) << endl;
  return 0;
}
