#include <bits/stdc++.h>
using namespace std;
const int mod1 = 1000000007;
const long long int mod2 = 998244353;
const int N = 1e5;
long long int countWays(vector<int> arr, int N) {
  long long int count[N + 1];
  memset(count, 0LL, sizeof(count));
  count[0] = 1LL;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < arr.size(); j++) {
      if (i >= arr[j]) count[i] = (count[i] + count[i - arr[j]]) % mod2;
    }
  }
  return count[N] % mod2;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  int l, r;
  set<int> s;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    s.insert(l);
    s.insert(r);
  }
  vector<int> a;
  for (int x : s) a.push_back(x);
  cout << countWays(a, n - 1) << "\n";
  return 0;
}
