#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int dp[5 * N], lazy[5 * N], n, k, a[20], b[20];
int mod = 998244353;
int sum(int x, int y) {
  x %= mod;
  y %= mod;
  return (x + y) % mod;
}
void Lazy(int p, int L, int R) {
  dp[p] = sum(dp[p], lazy[p]);
  if (L != R) {
    lazy[2 * p] = sum(lazy[p], lazy[2 * p]);
    lazy[2 * p + 1] = sum(lazy[p], lazy[2 * p + 1]);
  }
  lazy[p] = 0;
  return;
}
int get(int i, int p = 1, int L = 1, int R = n) {
  Lazy(p, L, R);
  if (L == R) return dp[p];
  if (i <= ((L + R) / 2)) return get(i, 2 * p, L, ((L + R) / 2));
  return get(i, 2 * p + 1, ((L + R) / 2) + 1, R);
}
void upd(int l, int r, int x, int p = 1, int L = 1, int R = n) {
  Lazy(p, L, R);
  if (l > R || r < L) return;
  if (L >= l && R <= r) {
    lazy[p] = x;
    Lazy(p, L, R);
    return;
  }
  upd(l, r, x, 2 * p, L, ((L + R) / 2));
  upd(l, r, x, 2 * p + 1, ((L + R) / 2) + 1, R);
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < k; i++) cin >> a[i] >> b[i];
  upd(1, 1, 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int L = i + a[j];
      int R = i + b[j];
      if (L > n) continue;
      R = min(R, n);
      upd(L, R, get(i));
    }
  }
  cout << get(n);
  return 0;
}
