#include <bits/stdc++.h>
using namespace std;
void solve(int n, vector<long long> &t, vector<int> &s) {
  if (n == 1) {
    return;
  }
  long long a = 0;
  for (int e : s) {
    if (n - e <= 0) {
      break;
    }
    if (t[n - e] == -1) {
      solve(n - e, t, s);
    }
    a = (a + t[n - e]) % 998244353;
  }
  t[n] = a;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s;
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    for (int li = l; li < r + 1; ++li) {
      s.push_back(li);
    }
  }
  sort(s.begin(), s.end());
  vector<long long> tables(n + 1);
  fill(tables.begin(), tables.end(), -1);
  tables[1] = 1;
  solve(n, tables, s);
  cout << (tables[n] % 998244353) << endl;
}
