#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> v;
  for (int i = 0; i < (k); ++i) {
    int x, y;
    cin >> x >> y;
    for (int i = x; i <= y; i++) {
      v.push_back(i);
    }
  }
  vector<int> dp(n + 1);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto x : v) {
      if (x < i) {
        dp[i] += dp[i - x];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n];
}
int main() {
  int y;
  y = 1;
  while (y--) {
    solve();
  }
}
