#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(11);
  vector<int> r(11);
  for (int i = 0; i < (int)(k); i++) cin >> l[i] >> r[i];
  vector<int> t(200005);
  int cnt = 0;
  for (int i = 0; i < (int)(k); i++) {
    for (int j = 0; j < (int)((r[i] - l[i] + 1)); j++) {
      t[cnt] = l[i] + j;
      cnt++;
    }
  }
  vector<int> dp(400005);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    if (dp[i] != 0) {
      for (int j = 0; j < cnt; j++) {
        dp[i + t[j]] += dp[i];
        dp[i + t[j]] %= 998244353;
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
