#include <bits/stdc++.h>
using namespace std;
long long const mod1 = 998244353;
long long const mod = 1000000007;
const long long inf = LLONG_MAX;
long long toint(const string &s) {
  stringstream ss;
  ss << s;
  long long x;
  ss >> x;
  return x;
}
string tostring(long long number) {
  stringstream ss;
  ss << number;
  return ss.str();
}
struct cmp {
  bool operator()(pair<long long, long long> a, pair<long long, long long> b) {
    return (a.first < b.first);
  }
};
long long modexp(long long x, long long n) {
  if (n == 0) {
    return 1;
  } else if (n & 1) {
    return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod;
  } else {
    return (modexp((x * x) % mod, n / 2) % mod);
  }
}
long long modinv(long long n) { return modexp(n, mod - 2); }
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long segm_tree[400001];
long long a[200001];
void recalculate(long long node) {
  segm_tree[node] = (segm_tree[2 * node] + segm_tree[2 * node + 1]) % mod1;
}
void build(long long node, long long left, long long right) {
  if (left == right) {
    segm_tree[node] = a[left];
  } else {
    long long middle = (left + right) / 2;
    build(2 * node, left, middle);
    build(2 * node + 1, middle + 1, right);
    recalculate(node);
  }
}
void update(long long node, long long left, long long right, long long x,
            long long y) {
  if (left == right) {
    segm_tree[node] = y;
  } else {
    long long middle = (left + right) / 2;
    if (x <= middle) {
      update(2 * node, left, middle, x, y);
    } else {
      update(2 * node + 1, middle + 1, right, x, y);
    }
    recalculate(node);
  }
}
long long query(long long node, long long left, long long right, long long x,
                long long y) {
  if (y < left or right < x) {
    return 0;
  }
  if (x <= left && right <= y) {
    return segm_tree[node];
  } else {
    long long middle = (left + right) / 2;
    long long p1 = query(2 * node, left, middle, x, y);
    long long p2 = query(2 * node + 1, middle + 1, right, x, y);
    return (p1 + p2) % mod1;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<pair<long long, long long> > v;
  long long n, k;
  cin >> n >> k;
  long long ans = 0;
  memset(a, 0, sizeof(a));
  a[1] = 1;
  build(1, 1, n);
  for (long long i = 0; i < k; i++) {
    long long x;
    long long y;
    cin >> x >> y;
    v.push_back({x, y});
  }
  for (long long i = 2; i <= n; i++) {
    long long temp = 0;
    for (auto x : v) {
      long long first = x.first;
      long long second = x.second;
      if (i - first >= 1) {
        long long qr = i - first;
        long long ql = max(1ll, i - second);
        temp += query(1, 1, n, ql, qr);
        temp %= mod1;
      }
    }
    a[i] = temp;
    update(1, 1, n, i, temp);
  }
  cout << a[n];
}
