#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

int main()
{
    ll n, m;
    cin >> n >> m;
    ll maL = -1;
    ll miR = n + 10;
    rep(i, m)
    {
        ll l, r;
        cin >> l >> r;
        maL = max(maL, l);
        miR = min(miR, r);
    }

    ll ans = max((ll)0, miR - maL + 1);
    cout << ans << endl;
}
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

template<typename t1, class t2>
void input(t1 count,t2 array) {
	for(t1 i = 0;i < count;i++) {
		cin >> array[i];
	}
}

template<typename t1, class t2>
void output(t1 count,t2 array) {
	for(t1 i = 0;i < count;i++) {
		cout << array[i];
		if(i != count - 1) cout << " ";
	}
	cout << endl;
}

int n,s[10000],t[500],q,c;

bool exists(int x) {
	for(int i = 0;i < n;i++) if(s[i] == x) return true;
	return false;
}

int main(int argc,char** argv) {
	cin >> n;
	input(n,s);
	cin >> q;
	input(q,t);
	for(int i = 0;i < q;i++) {
		if(exists(t[i]))c++;
	}
	cout << c << endl;
}

