#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
long long dp[210000];
int main() {
  int N, K;
  cin >> N >> K;
  int L[K];
  int R[K];
  int mod = 998244353;
  for (int i = 0; i < N; ++i) {
    cin >> L[i];
    cin >> R[i];
  }
  for (int i = 0; i < 210000; ++i) dp[i] = INF;
  dp[0] = 0;
  for (int i = 1; i < N; ++i) {
    int p = 0;
    for (int j = 0; j < (int)(i); j++) {
      if (L[lower_bound(L, L + K, i - j) - L] == i - j) {
        if (j != 0) {
          p += dp[j];
        } else {
          p += 1;
        }
      } else if (R[lower_bound(R, R + K, i - j) - R] == i - j) {
        if (j != 0) {
          p += dp[j];
        } else {
          p += 1;
        }
      }
    }
    dp[i] = p;
  }
  cout << dp[N - 1] << endl;
}
