#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
  vector<int> par;
  UnionFind(int n) : par(n, -1) {}
  void init(int n) { par.assign(n, -1); }
  int root(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  int size(int x) { return -par[root(x)]; }
};
int gcd(int a, int b) {
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int(i) = 0; (i) < (k); ++(i)) cin >> l[i] >> r[i];
  vector<int> imos(500100);
  int now = 1;
  int MOD = 998244353;
  for (int(pos) = 0; (pos) < (n - 1); ++(pos)) {
    now += imos[pos];
    now %= MOD;
    for (int(i) = 0; (i) < (k); ++(i)) {
      imos[pos + l[i]] += now;
      imos[pos + l[i]] %= MOD;
      imos[pos + r[i] + 1] -= now;
      imos[pos + r[i] + 1] %= MOD;
    }
  }
  cout << imos[n - 1] << endl;
}
