#include <bits/stdc++.h>
using namespace std;
int dp[200005];
void solve() {
  memset(dp, 0, sizeof(dp));
  ;
  vector<int> v;
  int n;
  cin >> n;
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) {
      v.push_back(j);
      dp[j + 1] = 1;
    }
  }
  sort(v.begin(), v.end());
  dp[0] = 0;
  dp[1] = 0;
  for (int i = 2; i <= n; i++) {
    auto it = v.begin();
    while (it != v.end()) {
      if (i - (*it) >= 1) {
        dp[i] = (dp[i] + dp[i - (*it)] % 998244353);
        dp[i] %= 998244353;
        it++;
      } else {
        break;
      }
    }
  }
  cout << dp[n];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  for (int I = 1; I <= t; I++) {
    solve();
  }
  return 0;
}
