#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

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

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
//#define pp pair<pii,pii>
const int hell=1000000007;



int power(int a,int b)
{
  if(b==0)return 1;
  if(b==1)return a;
  int t=power(a,b/2);
  t%=hell;
  t*=t;
  t%=hell;
  if(b%2)return (t*a)%hell;
  else
     return t;
}

int N=100010;

vi seg(4*N),lazy(4*N);
void build(ll cur,ll st,ll end)
{
  if(st==end)
  {
    seg[cur]=0;
    return;
  }
  ll mid=(st+end)>>1;
  build(2*cur,st,mid);
  build(2*cur+1,mid+1,end);
  seg[cur]=seg[2*cur]+seg[2*cur+1];          /* 1-change */
}
void updaterange(ll cur,ll st,ll end,ll l,ll r,ll val)
{
  if(lazy[cur]!=0)                                    /* 2-change */
  {
    seg[cur]+=(end-st+1)*lazy[cur];          /* 3-change */
    if(st!=end)
    {
      lazy[2*cur]+=lazy[cur];            /* 4-change */
      lazy[2*cur+1]+=lazy[cur];                   /* 5-change */
    }
    lazy[cur]=0;                                    /* 6-change */
  }
  if(st>end||st>r||end<l) return;
  if(l<=st&&end<=r)
  {
    seg[cur]+=(end-st+1)*val;              /* 7-change */
    if(st!=end)
    {
      lazy[2*cur]+=val;                           /* 8-change */
      lazy[2*cur+1]+=val;                         /* 9-change */
    }
    return;
  }
  ll mid=(st+end)>>1;
  updaterange(2*cur,st,mid,l,r,val);
  updaterange(2*cur+1,mid+1,end,l,r,val);
  seg[cur]=seg[2*cur]+seg[2*cur+1];                  /* 10-change */
}
ll query(ll cur,ll st,ll end,ll l,ll r)
{
  if(st>end||st>r||end<l) return 0;
  if(lazy[cur]!=0)
  {
    seg[cur]+=(end-st+1)*lazy[cur];                /* 11-change */
    if(st!=end)
    {
      lazy[2*cur]+=lazy[cur];                    /* 12-change */
      lazy[2*cur+1]+=lazy[cur];                  /* 13-change */
    }
    lazy[cur]=0;
  }
  if(st>=l&&end<=r) return seg[cur];
  ll mid=(st+end)>>1;
  ll ans1=query(2*cur,st,mid,l,r);
  ll ans2=query(2*cur+1,mid+1,end,l,r);
  return ans1+ans2;                                 /* 14-change */
}

int solve( ){


int n,m;
cin>>n>>m;
build(1,1,n);
rep(i,0,m)
{
  int x,y;
  cin>>x>>y;
  updaterange(1,1,n,x,y,1);
}
int ans=0;
rep(i,1,n+1)
{
  if(query(1,1,n,i,i)==m)ans++;
}
cout<<ans;


return 0;
}

signed main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);                                                                    


  clock_t time_req;

    // Without using pow function
                                                                                                                   

   // cin>>t;

    int k=1;
   while(t--)
     {
       //cout<<"case #"<<k<<":"<<" ";k++;
      solve();
     }

         time_req = clock() - time_req;
    //cout <<endl<< "Processor time taken is "
      //<< (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
} 

Measured memory_bytes: 6528