#include <bits/stdc++.h>
using namespace std;
using LLONG = long long;
const LLONG MOD = 998244353;
vector<pair<int, int>> lrs;
LLONG dp[200001];
LLONG Comp(int min, int max) {
  if (min > max) return 0;
  if (max <= 0) return 0;
  if (min == 1 && max == 1) {
    return 1;
  }
  LLONG ret = 0;
  for (const auto& lr : lrs) {
    if (lr.first == lr.second) {
      ret += Comp(min - lr.first, max - lr.first);
      ret %= MOD;
    } else {
      int nextMin = min - lr.second;
      int nextMax = max - lr.first;
      ret += Comp(nextMin, nextMin);
      ret %= MOD;
      ret += Comp(nextMin + 1, nextMax - 1) * 2;
      ret %= MOD;
      ret += Comp(nextMax, nextMax);
      ret %= MOD;
    }
  }
  return ret;
}
int main() {
  int N, K;
  cin >> N >> K;
  lrs = vector<pair<int, int>>(K);
  for (int i = 0; i < K; ++i) cin >> lrs[i].first >> lrs[i].second;
  dp[1] = 1;
  cout << Comp(N, N) << endl;
}
