Language: C++

///////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <typeinfo>
#include <numeric>

using namespace std;

///////////////////////////////////////////////////////////////////////////////

#define pb push_back
#define V vector
#define M unordered_map
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll, ll> t2;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

struct UnionFind
{
        unsigned ll *parent, *count, *rank;

        UnionFind(unsigned ll n) {
                parent = new unsigned ll[n+1];
                count = new unsigned ll[n+1];
                rank = new unsigned ll[n+1];
                for (unsigned ll i = 0ULL; i < n+1; ++i) {
                        parent[i] = i;
                        count[i] = 1;
                        rank[i] = 0;
                }
        }

        unsigned ll root(unsigned ll i) {
                if (parent[i] == i) return i;
                parent[i] = root(parent[i]);
                return parent[i];
        }

        void unite(unsigned ll i, unsigned ll j) {
                unsigned ll rooti = root(i);
                unsigned ll rootj = root(j);

                if (rooti == rootj) return;

                if (rank[rootj] < rank[rooti]) {
                        parent[i] = parent[j] = parent[rootj] = rooti;
                        count[rooti] += count[rootj];
                }
                else {
                        parent[i] = parent[j] = parent[rooti] = rootj;
                        count[rootj] += count[rooti];
                        if (rank[rootj] == rank[rooti]) rank[rootj]++;
                }
        }

        bool same(unsigned ll i, unsigned ll j) {
                return root(i) == root(j);
        }
};

void llin(ll &a)
{
        cin >> a;
}

void llinl1(auto &v, ll count)
{
        for (ll i = 0LL; i < count ; ++i) {
                ll a;
                cin >> a;
                v.push_back(a);
        }
}

void llinl2(auto &v, ll count)
{
        for (ll i = 0LL; i < count ; ++i) {
                ll a, b;
                cin >> a >> b;
                v.push_back(tuple<ll, ll>(a, b));
        }
}

void llinl3(auto &v, ll count)
{
        for (ll i = 0LL; i < count ; ++i) {
                ll a, b, c;
                cin >> a >> b >> c;
                v.push_back(tuple<ll, ll, ll>(a, b, c));
        }
}

void llina(auto &v, ll count)
{
        llinl1(v, count);
}

template <typename T>
T min(const V<T> v)
{
        T ret = v[0];
        for (auto i : v) ret = min(ret, i);
        return ret;
}

template <typename T>
T max(const V<T> v)
{
        T ret = v[0];
        for (auto i : v) ret = max(ret, i);
        return ret;
}

ll absll(ll x)
{
        if (x < 0) return -x;
        return x;
}

ll mod_pow(ll base, ll exp, ll mod)
{
        ll ret = 1LL;

        for ( ; exp; ) {
                if (exp & 1LL) {
                        ret *= base;
                        ret %= mod;
                }
                base = (base * base) % mod;
                exp >>= 1;
        }

        return ret;
}

ll mod_inv(ll x, ll mod)
{
        // available only when mod is prime
        return mod_pow(x, mod - 2LL, mod);
}

ll gcm(ll x, ll y)
{
        while (y != 0) {
                ll z = x % y;
                x = y;
                y = z;
        }
        return x;
}

template <typename T>
void sort(V<T> &v)
{
        sort(v.begin(), v.end());
}

template <typename T>
void sort_reverse(V<T> &v)
{
        sort(v.begin(), v.end(), greater<T>());
}

void get_divisors(V<ll> &retlist, ll x)
{
        for (ll i = 1LL; i < sqrt(x) + 3LL; ++i) {
                if (x % i == 0LL) {
                        retlist.push_back(i);
                        retlist.push_back(x / i);
                }
        }
}

void get_factors(V<ll> &retlist, ll x)
{
        for (ll i = 2LL; i < (ll)(sqrt(x)) + 3LL; ++i) {
                while (x % i == 0LL) {
                        retlist.pb(i);
                        x /= i;
                }
        }
        retlist.pb(x);
}

template <typename T>
void intersection(const set<T> &a, const set<T> &b,
                  set<T> &result)
{
        V<T> resultlist;

        set_intersection(a.begin(), a.end(),
                         b.begin(), b.end(),
                         back_inserter(resultlist));

        set<T> resultset(resultlist.begin(), resultlist.end());
        result = resultset;
}

unsigned ll combination(ll x, ll y)
{
        if (y > x / 2LL) y = x - y;

        unsigned ll ret = 1LL;
        for (ll i = 0LL; i < y; ++i) {
                ret *= x--;
                ret /= (i + 1LL);
        }

        return ret;
}

unsigned ll mod_combination(ll x, ll y, ll mod)
{
        if (y > x / 2LL) y = x - y;

        ll ret = 1;

        for (ll i = 0LL; i < y; ++i) {
                ret = (ret * x--) % mod;
                ret = (ret * mod_inv(i + 1LL, mod)) % mod;
        }

        return ret;
}

void make_linklist(const V<tuple<ll, ll>> &srclist, V<V<ll>> &dstlist)
{
        for (auto src : srclist) {
                ll a = get<0>(src);
                ll b = get<1>(src);
                dstlist[a].pb(b);
                dstlist[b].pb(a);
        }
}

void debug_print(auto xlist)
{
        for (auto x : xlist) cout << "-- " << x << endl;
}

int _main();
int main()
{
        cout << setprecision(12);
        return _main();
}

///////////////////////////////////////////////////////////////////////////////

typedef tuple<ll, ll> t2;

int _main()
{
        ll n, m;
        llin(n); llin(m);

        V<t2> lrlist;
        llinl2(lrlist, m);

        ll lmax = -1LL, rmin = n + 10LL;
        for (auto lr : lrlist) {
                ll l = get<0>(lr);
                ll r = get<1>(lr);
                lmax = max(lmax, l);
                rmin = min(rmin, r);
        }

        cout << max(0LL, rmin - lmax + 1);

        return 0;
}

///////////////////////////////////////////////////////////////////////////////


Compiler output:
a.cc:34:18: error: expected ';' at end of member declaration
   34 |         unsigned ll *parent, *count, *rank;
      |                  ^~
      |                    ;
a.cc:34:22: error: ISO C++ forbids declaration of 'parent' with no type [-fpermissive]
   34 |         unsigned ll *parent, *count, *rank;
      |                      ^~~~~~
a.cc:34:31: error: ISO C++ forbids declaration of 'count' with no type [-fpermissive]
   34 |         unsigned ll *parent, *count, *rank;
      |                               ^~~~~
a.cc:34:39: error: ISO C++ forbids declaration of 'rank' with no type [-fpermissive]
   34 |         unsigned ll *parent, *count, *rank;
      |                                       ^~~~
a.cc:36:31: error: expected ',' or '...' before 'n'
   36 |         UnionFind(unsigned ll n) {
      |                               ^
a.cc:47:18: error: expected ';' at end of member declaration
   47 |         unsigned ll root(unsigned ll i) {
      |                  ^~
      |                    ;
a.cc:47:18: error: redeclaration of 'unsigned int UnionFind::ll'
a.cc:34:18: note: previous declaration 'unsigned int UnionFind::ll'
   34 |         unsigned ll *parent, *count, *rank;
      |                  ^~
a.cc:47:38: error: expected ',' or '...' before 'i'
   47 |         unsigned ll root(unsigned ll i) {
      |                                      ^
a.cc:47:21: error: ISO C++ forbids declaration of 'root' with no type [-fpermissive]
   47 |         unsigned ll root(unsigned ll i) {
      |                     ^~~~
a.cc:53:32: error: expected ',' or '...' before 'i'
   53 |         void unite(unsigned ll i, unsigned ll j) {
      |                                ^
a.cc:70:31: error: expected ',' or '...' before 'i'
   70 |         bool same(unsigned ll i, unsigned ll j) {
      |                               ^
a.cc: In constructor 'UnionFind::UnionFind(unsigned int)':
a.cc:37:26: error: invalid conversion from 'unsigned int*' to 'int*' [-fpermissive]
   37 |                 parent = new unsigned ll[n+1];
      |                          ^~~~~~~~~~~~
      |                          |
      |                          unsigned int*
a.cc:37:39: error: expected ';' before 'll'
   37 |                 parent = new unsigned ll[n+1];
      |                                       ^~
a.cc:38:25: error: invalid conversion from 'unsigned int*' to 'int*' [-fpermissive]
   38 |                 count = new unsigned ll[n+1];
      |                         ^~~~~~~~~~~~
      |                         |
      |                         unsigned int*
a.cc:38:38: error: expected ';' before 'll'
   38 |                 count = new unsigned ll[n+1];
      |                                      ^~
a.cc:39:24: error: invalid conversion from 'unsigned int*' to 'int*' [-fpermissive]
   39 |                 rank = new unsigned ll[n+1];
      |                        ^~~~~~~~~~~~
      |                        |
      |                        unsigned int*
a.cc:39:37: error: expected ';' before 'll'
   39 |                 rank = new unsigned ll[n+1];
      |                                     ^~
a.cc:40:34: error: expected ';' before 'i'
   40 |                 for (unsigned ll i = 0ULL; i < n+1; ++i) {
      |                                  ^
a.cc:40:34: error: 'i' was not declared in this scope
a.cc:40:48: error: 'n' was not declared in this scope; did you mean 'yn'?
   40 |                 for (unsigned ll i = 0ULL; i < n+1; ++i) {
      |                                                ^
      |                                                yn
a.cc:40:51: error: expected ')' before ';' token
   40 |                 for (unsigned ll i = 0ULL; i < n+1; ++i) {
      |                                                   ^
a.cc:40:21: note: to match this '('
   40 |                 for (unsigned ll i = 0ULL; i < n+1; ++i) {
      |                     ^
a.cc:40:55: error: 'i' was not declared in this scope
   40 |                 for (unsigned ll i = 0ULL; i < n+1; ++i) {
      |                                                       ^
a.cc: In member function 'int UnionFind::root(unsigned int)':
a.cc:48:28: error: 'i' was not declared in this scope
   48 |                 if (parent[i] == i) return i;
      |                            ^
a.cc:49:24: error: 'i' was not declared in this scope
   49 |                 parent[i] = root(parent[i]);
      |                        ^
a.cc: In member function 'void UnionFind::unite(unsigned int)':
a.cc:54:29: error: expected initializer before 'rooti'
   54 |                 unsigned ll rooti = root(i);
      |                             ^~~~~
a.cc:55:29: error: expected initializer before 'rootj'
   55 |                 unsigned ll rootj = root(j);
      |                             ^~~~~
a.cc:57:21: error: 'rooti' was not declared in this scope; did you mean 'root'?
   57 |                 if (rooti == rootj) return;
      |                     ^~~~~
      |                     root
a.cc:57:30: error: 'rootj' was not declared in this scope; did you mean 'root'?
   57 |                 if (rooti == rootj) return;
      |                              ^~~~~
      |                              root
a.cc:59:26: error: 'rootj' was not declared in this scope; did you mean 'root'?
   59 |                 if (rank[rootj] < rank[rooti]) {
      |                          ^~~~~
      |                          root
a.cc:59:40: error: 'rooti' was not declared in this scope; did you mean 'root'?
   59 |                 if (rank[rootj] < rank[rooti]) {
      |                                        ^~~~~
      |                                        root
a.cc:60:32: error: 'i' was not declared in this scope
   60 |                         parent[i] = parent[j] = parent[rootj] = rooti;
      |                                ^
a.cc:60:44: error: 'j' was not declared in this scope; did you mean 'jn'?
   60 |                         parent[i] = parent[j] = parent[rootj] = rooti;
      |                                            ^
      |                                            jn
a.cc:64:32: error: 'i' was not declared in this scope
   64 |                         parent[i] = parent[j] = parent[rooti] = rootj;
      |                                ^
a.cc:64:44: error: 'j' was not declared in this scope; did you mean 'jn'?
   64 |                         parent[i] = parent[j] = parent[rooti] = rootj;
      |                                            ^
      |                                            jn
a.cc: In member function 'bool UnionFind::same(unsigned int)':
a.cc:71:29: error: 'i' was not declared in this scope
   71 |                 return root(i) == root(j);
      |                             ^
a.cc:71:40: error: 'j' was not declared in this scope; did you mean 'jn'?
   71 |                 return root(i) == root(j);
      |                                        ^
      |                                        jn
a.cc: At global scope:
a.cc:80:13: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   80 | void llinl1(auto &v, ll count)
      |             ^~~~
a.cc:89:13: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   89 | void llinl2(auto &v, ll count)
      |             ^~~~
a.cc:98:13: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   98 | void llinl3(auto &v, ll count)
      |             ^~~~
a.cc:107:12: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
  107 | void llina(auto &v, ll count)
      |            ^~~~
a.cc:213:13: error: expected initializer before 'combination'
  213 | unsigned ll combination(ll x, ll y)
      |             ^~~~~~~~~~~
a.cc:226:13: error: expected initializer before 'mod_combination'
  226 | unsigned ll mod_combination(ll x, ll y, ll mod)
      |             ^~~~~~~~~~~~~~~
a.cc:250:18: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
  250 | void debug_print(auto xlist)
      |                  ^~~~