#include <bits/stdc++.h>
static const long long int MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const long long int MOD = 1e9 + 7;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const long long int MAX_N = 11000;
vector<long long int> mem(MAX_N, 0);
int main() {
  long long int n, k, l, r;
  cin >> n >> k;
  vector<long long int> v;
  for (int i = 0; i < (int)(k); i++) {
    cin >> l >> r;
    for (int i = l; i <= r; i++) v.push_back(i);
  }
  sort(v.begin(), v.end());
  mem[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < (int)(v.size()); j++) {
      if (i - v[j] <= 0)
        break;
      else {
        if (i - v[j] != 1 && mem[i - v[j]] == 0) continue;
        mem[i] += mem[i - v[j]];
        mem[i] %= 998244353;
      }
    }
  }
  cout << mem[n];
}
