#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define all(v) (v).begin(),(v).end()
using ll = long long;
constexpr ll INF = 1e18;
constexpr ll MOD = 998244353;

// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

int main(void) {
    ll N, K;
    cin >> N >> K;
    vector<ll> L(K), R(K);
    for (ll i = 0; i < K; i++) {
        cin >> L[i] >> R[i];
    }

    vector<ll> map(N*3);
    // vector<ll> dmap(N*2);
    map[0] = 0;
    map[1] = -1;
    ll c = 1;
    for (ll i = 0; i < N; i++) {
        c += map[i];
        for (ll j = 0; j < K; j++) {
            map[i+L[j]] = (map[i+L[j]] + c) % MOD;
            map[i+R[j]+1] = mod((map[i+R[j]+1] - c) % MOD, MOD);
        }
    }
    cout << c << endl;
    return 0;
}
