#include <bits/stdc++.h>
using namespace std;
void sep() { cout << "-------------BLOCK-----------------\n"; }
template <typename T>
void debugv(vector<T> arr) {
  for (auto t : arr) cout << t << " ";
  cout << "\n";
}
template <typename T>
void debugarr(T arr, int n) {
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << "\n";
}
const int maxn = 1e5 + 1;
long long arr[maxn], n, m, t, k;
unordered_map<long long, long long> u;
long long __min(long long a, long long b) { return a < b ? a : b; }
long long __max(long long a, long long b) { return a > b ? a : b; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  long long a, b;
  set<long long> s;
  for (int i = 0; i < k; i++) {
    cin >> a >> b;
    if (b < a) {
      long long t = b;
      b = a;
      a = t;
    }
    for (int j = a; j <= b; j++) s.insert(j);
  }
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (set<long long>::iterator itr = s.begin(); itr != s.end(); itr++) {
      if (i - *itr < 0) break;
      dp[i] = (dp[i] + dp[i - *itr]) % 998244353;
    }
  }
  cout << dp[n] % 998244353 << endl;
}
