/*input
5 2
1 1
3 4

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int n, k;
int lft[11], rght[11];

int dp[200005];

struct data1 {
  // Use required attributes
 
  ll sum;
 
  // Default Values
  data1() : sum(0) {};
};
 
struct SegTree {
  int N;
  vector<struct data1> seg;
  vector<bool> cLazy;
  vector<ll> lazy;
 
  void init(int n) {
    N = n;
    seg.resize(4 * N + 5);
    cLazy.assign(4 * N + 5, false);
    lazy.assign(4 * N + 5, 0);
  }
 
  // Write reqd merge functions
  void merge(struct data1 &cur, struct data1 &l, struct data1 &r) {
    cur.sum = add(l.sum, r.sum);
  }
 
  // Handle lazy propagation appriopriately
  void propagate(int node, int L, int R) {
    if (L != R) {
      cLazy[node * 2] = 1;
      cLazy[node * 2 + 1] = 1;
      lazy[node * 2] = add(lazy[node * 2], lazy[node]);
      lazy[node * 2 + 1] = add(lazy[node * 2 + 1], lazy[node]);
    }
    seg[node].sum = add(seg[node].sum, mul((R - L + 1), lazy[node]));
    lazy[node] = 0;
    cLazy[node] = 0;
  }
 
  void build(int node, int L, int R) {
    if (L == R) {
      return;
    }
    int M = (L + R) / 2;
    build(node * 2, L, M);
    build(node * 2 + 1, M + 1, R);
    merge(seg[node], seg[node * 2], seg[node * 2 + 1]);
  }
 
  struct data1 Query(int node, int L, int R, int i, int j) {
    if (cLazy[node])
      propagate(node, L, R);
    if (j < L || i > R)
      return data1();
    if (i <= L && R <= j)
      return seg[node];
    int M = (L + R) / 2;
    struct data1 left = Query(node * 2, L, M, i, j);
    struct data1 right = Query(node * 2 + 1, M + 1, R, i, j);
    struct data1 cur;
    merge(cur, left, right);
    return cur;
  }
 
  struct data1 pQuery(int node, int L, int R, int pos) {
    if (cLazy[node])
      propagate(node, L, R);
    if (L == R)
      return seg[node];
    int M = (L + R) / 2;
    if (pos <= M)
      return pQuery(node * 2, L, M, pos);
    else
      return pQuery(node * 2 + 1, M + 1, R, pos);
  }
 
  void Update(int node, int L, int R, int i, int j, int val) {
    if (cLazy[node])
      propagate(node, L, R);
    if (j < L || i > R)
      return;
    if (i <= L && R <= j) {
      cLazy[node] = 1;
      lazy[node] = val;
      propagate(node, L, R);
      return;
    }
    int M = (L + R) / 2;
    Update(node * 2, L, M, i, j, val);
    Update(node * 2 + 1, M + 1, R, i, j, val);
    merge(seg[node], seg[node * 2], seg[node * 2 + 1]);
  }
 
  void pUpdate(int node, int L, int R, int pos, int val) {
    if (cLazy[node])
      propagate(node, L, R);
    if (L == R) {
      cLazy[node] = 1;
      lazy[node] += val;
      propagate(node, L, R);
      return;
    }
    int M = (L + R) / 2;
    if (pos <= M)
      pUpdate(node * 2, L, M, pos, val);
    else
      pUpdate(node * 2 + 1, M + 1, R, pos, val);
    merge(seg[node], seg[node * 2], seg[node * 2 + 1]);
  }
 
  struct data1 query(int pos) { return pQuery(1, 1, N, pos); }
 
  struct data1 query(int l, int r) { return Query(1, 1, N, l, r); }
 
  void update(int pos, int val) { pUpdate(1, 1, N, pos, val); }
 
  void update(int l, int r, int val) { Update(1, 1, N, l, r, val); }
};

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  mod = 998244353;

  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> lft[i] >> rght[i];
  } 

  SegTree obj;
  obj.init(200005);

  obj.update(1, 1);
  // dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    // dp[i] = add(dp[i], dp[i - 1]);
    // trace(i, dp[i]);
    // if (dp[i] == 0) continue;
    for (int j = 0; j < k; j++) {
      int l = lft[j], r = rght[j];
      int x = i + l, y = min(n, i + r);
      if (x > n) continue;
      // trace(i, l, r, x, y, dp[i]);
      // dp[x] = add(dp[x], dp[i]);
      // dp[y + 1] = sub(dp[y + 1], dp[i]);
      int v = obj.query(i).sum;
      obj.update(x, y, v);
      // while (x <= y) {
      //   // trace(i, x, dp[i]);
      //   dp[x] = add(dp[x], dp[i]);
      //   x++;
      // }
      // dp[x] = add(dp[x], dp[i]);
      // dp[y + 1] = sub(dp[y + 1], dp[i]);
    }
  }

  // dp[1] = sub(dp[1], 1);

  // for (int i = 1; i <= n; i++)
  //   dp[i] = add(dp[i], dp[i - 1]);

  cout << obj.query(n).sum << endl;

  return 0;
}

Measured memory_bytes: 15888