#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 100;
const int S = 5e5 + 100;
const ll MOD = 998244353;
ll dp[S] = {0};
void add(int id, ll x) {
  x %= MOD;
  while (id < S) {
    dp[id] += x;
    dp[id] %= MOD;
    id += id & -id;
  }
}
ll getVal(int id) {
  ll res = 0;
  while (id > 0) {
    res += dp[id];
    res %= MOD;
    id -= id & -id;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> seg(k);
  for (int i = 0; i < k; i++) {
    cin >> seg[i].first >> seg[i].second;
  }
  add(1, 1);
  add(2, -1);
  for (int pos = 1; pos < n; pos++) {
    for (const auto it : seg) {
      add(pos + it.first, getVal(pos));
      add(pos + it.second + 1, -getVal(pos));
    }
  }
  cout << getVal(n) << '\n';
  return 0;
}
