#include <bits/stdc++.h>
using namespace std;
int n, k;
int count;
int ss(int n, int *l, int *r) {
  int i, j;
  for (i = k; i >= 1; i--) {
    for (j = r[i]; j >= l[i]; j--) {
      if (n - j == 0) {
        ::count++;
      }
      if (n - j > 0) ss(n - j, l, r);
    }
  }
}
int main() {
  int i;
  int count = 0;
  int l[1000], r[1000];
  cin >> n >> k;
  for (i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  n--;
  ss(n, l, r);
  cout << ::count;
  return 0;
}
