#include <bits/stdc++.h>
using namespace std;
vector<int> steps;
vector<int> vis(200000, 0);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  int num = 0;
  vis[1] = 1;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    num += b - a + 1;
    for (int j = a; j <= b; j++) steps.push_back(j);
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) continue;
    for (int j = 0; j < num; j++) {
      if (i + steps[j] > n) continue;
      int ad = (vis[i + steps[j]] + vis[i]) % 998244353;
      if (ad == 0 && i + steps[j] < n) ad = 998244353;
      vis[i + steps[j]] = ad;
    }
  }
  cout << vis[n] << '\n';
  return 0;
}
