#include <bits/stdc++.h>
using namespace std;
static int my_speed_up = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  return 0;
}();
using ll = long long;
using ull = unsigned long long;
template <class T>
using v = vector<T>;
template <class T>
using vv = vector<vector<T>>;
template <class T>
using vvv = vector<vector<vector<T>>>;
template <class T>
using vvvv = vector<vector<vector<vector<T>>>>;
template <class T1, class T2>
using um = unordered_map<T1, T2>;
template <class T>
using us = unordered_set<T>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T, class... Ts>
void what_are_2(T const& arg, Ts const&... args) {
  cout << arg;
  if constexpr (sizeof...(args) > 0) {
    cout << ", ";
    what_are_2(args...);
  }
}
vv<int> d4 = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
vv<int> d8 = {{1, 0}, {-1, 0}, {0, 1},  {0, -1},
              {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
bool is_valid_pos(size_t w, size_t h, int x, int y) {
  return x >= 0 && x < static_cast<int>(w) && y >= 0 && y < static_cast<int>(h);
}
int main() {
  int N, K;
  cin >> N >> K;
  v<pii> ranges(K);
  for (int i = 0; i < (K); ++i) cin >> ranges[i].first >> ranges[i].second;
  v<int> rangesi;
  for (auto& range : ranges) {
    for (int j = range.first; j < (range.second + 1); ++j) rangesi.push_back(j);
  }
  sort(rangesi.begin(), rangesi.end());
  ull mod = 998244353;
  v<ull> tb(N, 0);
  tb[0] = 1;
  for (int i = 0; i < (tb.size()); ++i) {
    for (auto j : rangesi) {
      if (i + j >= tb.size()) break;
      tb[i + j] = (tb[i + j] + tb[i]) % mod;
    }
  }
  cout << tb.back() << endl;
  return 0;
}
