#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<array<long long, 2>> a(k);
  vector<long long> dp(n, 0);
  for (int i = 0; i < k; i++) {
    cin >> a[i][0] >> a[i][1];
  }
  dp[0] = 1;
  for (long long i = 0; i < n; i++) {
    for (auto j : a) {
      for (long long s = j[0]; s <= j[1]; s++) {
        if (i >= s) {
          dp[i] = (dp[i] + dp[i - s]) % (long long)998244353;
        } else {
          break;
        }
      }
    }
  }
  cout << dp[n - 1];
  return 0;
}
