#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using Grid = vector<vector<char>>;
using vin = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vbl = vector<bool>;
using vch = vector<char>;
using pnn = pair<int, int>;
string yes = "Yes", no = "No";
ll mod = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  vll l(k), r(k);
  for (int i = 0; i < (int)(k); i++) cin >> l[i] >> r[i];
  vll dp(n + 1, 0);
  for (int i = 0; i < (int)(k); i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      dp[j]++;
    }
  }
  for (int i = 0; i < (int)(n); i++) {
    if (dp[i] == 0) continue;
    for (int j = 0; j < (int)(k); j++) {
      for (int w = l[j]; w <= r[j]; w++) {
        if (w + i > n) break;
        dp[w + i] += dp[i];
        dp[w + i] %= mod;
      }
    }
  }
  cout << dp[n - 1] << endl;
}
