#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,lessl<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define double long double

#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()

#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define endl "\n"

#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)

#define bp __builtin_popcountll
#define inf 1e18

const int N=1e5+5;
const int M=1e9+7;
void solve()
{
     int n, k;
   cin >> n >> k;

   int a[k][2];
   for(int i=0 ; i<k ; i++)   cin >> a[i][0] >> a[i][1];

   vector<int> dp(n+5, 0);
   vector<int> p(n+5, 0);

   int pref = 0;
   dp[1] = 1;

   for(int i=1 ; i<=n ; i++){
      int cur = (pref + dp[i])%M;
      for(int j=0 ; j<k ; j++){
         int l = i + a[j][0];
         int r = i + a[j][1];
         if(l <= n){
            dp[l] = (dp [l] + cur)%M;
         }
         if(r + 1 <= n){
            dp[r + 1] = (dp[r + 1] - cur)%M;
            dp[r + 1] = (dp[r + 1] + M)%M;
         }
      }
      pref = (pref + dp[i])%M;
   }

   cout << dp[n] << endl;

}

signed main()
{
    FAST
    
    #ifndef ONLINE_JUDGE
    freopen("input_sublime.txt", "r", stdin);
    freopen("output_sublime.txt", "w", stdout);
    #endif
    
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
        // cout<<"Case #"<<tc<<": ";
        solve();
    }
    
    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}
