#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> jumps;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      jumps.push_back(j);
    }
  }
  sort(jumps.begin(), jumps.end());
  vector<long long int> ways(n + 1, 0);
  ways[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int d : jumps) {
      if (i + d > n) {
        break;
      }
      ways[i + d] = (ways[i + d] + ways[i]) % MOD;
    }
  }
  cout << ways[n] << "\n";
  return 0;
}
