#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
typedef vector<pair<int, int>> vp;
typedef vector<tuple<int, int, int>> vt;
template <typename tuple<int, int, int>>
istream& operator>>(istream& i, vector<tuple<int, int, int>>& v) {
  for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j];
  return i;
}
template <typename tuple<int, int, int>>
ostream& operator<<(ostream& o, const vector<tuple<int, int, int>>& v) {
  if ((int)(v).size()) o << join(v);
  return o;
}
template <typename T1, typename T2>
istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& v) {
  return o << v.first << "," << v.second;
}
template <typename tuple<int, int, int>>
bool mins(tuple<int, int, int>& x, const tuple<int, int, int>& y) {
  if (x > y) {
    x = y;
    return true;
  } else
    return false;
}
template <typename tuple<int, int, int>>
bool maxs(tuple<int, int, int>& x, const tuple<int, int, int>& y) {
  if (x < y) {
    x = y;
    return true;
  } else
    return false;
}
template <typename tuple<int, int, int>>
ll suma(const vector<tuple<int, int, int>>& a) {
  ll res(0);
  for (auto&& x : a) res += x;
  return res;
}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1e9 + 7;
using Graph = vector<vector<int>>;
vector<int> dp;
int n;
set<int> st;
int dfs(int A) {
  if (A == 0) return 1;
  if (A < 0) return 0;
  if (dp[A] >= 0) return dp[A];
  int ans = 0;
  for (auto i : st) {
    ans += dfs(A - i);
    ans %= 998244353;
  }
  return dp[A] = ans;
}
int main() {
  cin >> n;
  n--;
  int k;
  cin >> k;
  for (int i = 0; i < (k); ++i) {
    int a, b;
    cin >> a >> b;
    b++;
    for (int j = a; j < b; ++j) {
      st.insert(j);
    }
  }
  dp = vector<int>(n + 1, -1);
  cout << dfs(n) << endl;
}
