#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long inf = 9e18 + 9;
const int mod = 998244353;
long long res;
void solve() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  set<int> jump;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    jump.insert(x);
    jump.insert(y);
  }
  vector<int> v;
  for (auto it : jump) {
    v.push_back(it);
  }
  int dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto it : v) {
      if ((i - it) >= 0) {
        dp[i] += dp[i - it];
        dp[i] %= mod;
      }
    }
  }
  cout << (dp[n]) % mod << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}
