#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
const int H = 998244353;
long long n, res, dem, d, sum, k;
long long f[N];
vector<int> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen("test"
            ".inp",
            "r")) {
    freopen(
        "test"
        ".inp",
        "r", stdin);
    freopen(
        "test"
        ".out",
        "w", stdout);
  }
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end());
  f[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto j : v) {
      if (j > i) break;
      f[i] = (f[i] + f[i - j]) % H;
    }
  }
  cout << f[n];
}
