#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=1e5+10;
struct apple{
    int x,id,f;
    bool operator <(const apple &other)
    const {
        return x<other.x||(x==other.x&&f>other.f)||(x==other.x&&f==other.f&&id<other.id);
    }
}node[N*2];
int h[N*2];
int que[10];
int f[1030],ff[1030];
int now;
int get_num(int x)
{
    int ans=0;
    while(x)
    {
        if(x&1)
            ans++;
        x>>=1;
    }
    return ans;
}
void del(int id)
{
    int pos,i,j;
    for(pos=1;pos<=now;pos++)
        if(que[pos]==id)
            break;
    for(i=0;i<(1<<now);i++)
        ff[i]=0;
    for(i=0;i<(1<<now);i++)
    {
        j=i%(1<<(pos-1))+((i>>pos)<<(pos-1));
        ff[j]=max(ff[j],f[i]);
    }
    now--;
    for(i=pos;i<=now;i++)
        que[i]=que[i+1];
    for(i=0;i<(1<<now);i++)
        f[i]=ff[i];
}
void ins(int id)
{
    int i;
    for(i=0;i<(1<<now);i++)
        f[(1<<now)+i]=f[i];
    que[++now]=id;
}
void solve(int id)
{
    int i;
    for(i=0;i<(1<<now);i++)
        if(get_num(i)%2==1)
            f[i]+=h[id+1]-h[id];
    /*for(i=1;i<=now;i++)
        printf("%d ",que[i]);
    printf("\n");
    for(i=0;i<(1<<now);i++)
        printf("%d ",f[i]);
    printf("\n\n");*/
}
int main()
{
    int n,m,k,cnt,l,i,j,r,ans=0;
    cnt=0;
    scanf("%d%d%d",&n,&m,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&l,&r);
        h[++cnt]=l;
        node[cnt].x=l;
        node[cnt].f=0;
        node[cnt].id=i;
        h[++cnt]=r+1;
        node[cnt].x=r+1;
        node[cnt].f=1;
        node[cnt].id=i;
    }
    h[++cnt]=m+1;
    sort(h+1,h+cnt+1);
    l=unique(h+1,h+cnt+1)-h-1;
    /*printf("<%d>",l);
    for(i=1;i<=l;i++)
        printf("%d ",h[i]);
    printf("\n");*/
    sort(node+1,node+cnt);
    j=1;
    now=0;
    for(i=1;i<=l;i++)
    {
        while(j<cnt&&node[j].x<=h[i])
        {
            if(node[j].f==0)
                ins(node[j].id);
            else
                del(node[j].id);
            j++;
        }
        solve(i);
    }
    for(i=0;i<(1<<now);i++)
        ans=max(ans,f[i]);
    printf("%d",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=1e5+10;
struct apple{
    int x,id,f;
    bool operator <(const apple &other)
    const {
        return x<other.x||(x==other.x&&f>other.f)||(x==other.x&&f==other.f&&id<other.id);
    }
}node[N*2];
int h[N*2];
int que[10];
int f[1030],ff[1030];
int now;
int get_num(int x)
{
    int ans=0;
    while(x)
    {
        if(x&1)
            ans++;
        x>>=1;
    }
    return ans;
}
void del(int id)
{
    int pos,i,j;
    for(pos=1;pos<=now;pos++)
        if(que[pos]==id)
            break;
    for(i=0;i<(1<<now);i++)
        ff[i]=0;
    for(i=0;i<(1<<now);i++)
    {
        j=i%(1<<(pos-1))+(i>>pos)<<(pos-1);
        ff[j]=max(ff[j],f[i]);
    }
    now--;
    for(i=pos;i<=now;i++)
        que[i]=que[i+1];
    for(i=0;i<(1<<now);i++)
        f[i]=ff[i];
}
void ins(int id)
{
    int i;
    for(i=0;i<(1<<now);i++)
        f[(1<<now)+i]=f[i];
    que[++now]=id;
}
void solve(int id)
{
    int i;
    for(i=0;i<(1<<now);i++)
        if(get_num(i)%2==1)
            f[i]+=h[id+1]-h[id];
    /*for(i=1;i<=now;i++)
        printf("%d ",que[i]);
    printf("\n");
    for(i=0;i<(1<<now);i++)
        printf("%d ",f[i]);
    printf("\n\n");*/
}
int main()
{
    int n,m,k,cnt,l,i,j,r,ans=0;
    cnt=0;
    scanf("%d%d%d",&n,&m,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&l,&r);
        h[++cnt]=l;
        node[cnt].x=l;
        node[cnt].f=0;
        node[cnt].id=i;
        h[++cnt]=r+1;
        node[cnt].x=r+1;
        node[cnt].f=1;
        node[cnt].id=i;
    }
    h[++cnt]=m+1;
    sort(h+1,h+cnt+1);
    l=unique(h+1,h+cnt+1)-h-1;
    /*printf("<%d>",l);
    for(i=1;i<=l;i++)
        printf("%d ",h[i]);
    printf("\n");*/
    sort(node+1,node+cnt);
    j=1;
    now=0;
    for(i=1;i<=l;i++)
    {
        while(j<cnt&&node[j].x<=h[i])
        {
            if(node[j].f==0)
                ins(node[j].id);
            else
                del(node[j].id);
            j++;
        }
        solve(i);
    }
    for(i=0;i<(1<<now);i++)
        ans=max(ans,f[i]);
    printf("%d",ans);
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

const int N = 1e5 + 5, K = 8;
int dp[1 << K];
int val[K] = {}, cur[K] = {};
int par[1 << K];

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,m,k;
	cin >> n >> m >> k;
	vector<array<int,2>> v(n);
	rep(i,0,1 << k)par[i] = __builtin_popcount(i) % 2;
	rep(i,1,n+1){
		int l,r;
		cin >> l >> r;
		v.push_back(array<int,2>{l,i});
		v.push_back(array<int,2>{r+1,-i});
	}
	sort(all(v));
	memset(dp,-1,sizeof(dp));
	dp[0] = 0;
	int cur, pri=0;
	rep(i,0,v.size()){
		int cur = v[i][0];
		rep(i,0,1 << k)if(~dp[i])dp[i] += par[i] * (cur - pri);
		pri = cur;
		int id = v[i][1];
		if(id < 0){
			id = -id;
			int bit = 0;
			rep(i,0,k){
				if(val[i] == id){
					bit = i;
				}
			}
			rep(i,0,1 << k){
				if((i >> bit) & 1){
					gmax(dp[i ^(1 << bit)], dp[i]);
					dp[i] = -1;
				}
			}
			val[bit] = 0;
		}
		else{
			int bit = 0;
			rep(i,0,k){
				if(val[i] == 0){
					val[i] = id;
					bit = i;
					break;
				}
			}
			rep(i,0,1 << k){
				if(((i >> bit)&1) == 0){
					dp[i | (1 << bit)] = dp[i];
				}
			}
		}
	}
	int ans = *max_element(begin(dp), end(dp));
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

const int N=1e5+5, K=8;
int dp[N][K], taken[N][K];

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,m,k;
	cin >> n >> m >> k;
	vector<array<int,2>> v(n);
	vector<int> type(n);
	rep(i,0,n)cin >> v[i][0] >> v[i][1];
	sort(all(v));
	int taken[K] = {};
	rep(i,0,n){
		rep(j,0,K){
			if(taken[j] <= v[i][0]){
				taken[j] = v[i][1] + 1;
				type[i] = j;
				break;
			}
		}
	}
	int d[K] = {};
	int cur = 1;
	v.push_back(array<int,2>({m+1,m+1}));
	rep(i,0,n+1){
		int curx = cur;
		rep(msk,0,1 << k){
			int on = __builtin_popcount(msk) % 2;
			bool val = 1;
			rep(j,0,k)if(((msk >> j)&1) && d[j] == 0)val = 0;
			if(!val)continue;

			// take
			vector<int> tmp;
			int nxt = msk;
			rep(j,0,k){
				if(d[j] < v[i][0]){
					tmp.push_back(d[j]);
				 	nxt ^= 1 << j;
				}
			}
			tmp.push_back(cur);
			tmp.push_back(v[i][0]);
			sort(all(tmp));
			int add = 0;
			rep(j,0,tmp.size()-1){
				add += on * (tmp[j+1] - tmp[j]);
				on ^= 1;
			}
			gmax(dp[i+1][nxt],dp[i][msk] + add);
		}
		d[type[i]] = v[i][1];
		cur = v[i][0];
	}
	int ans = 0;
	rep(msk,0, 1<< k){
		gmax(ans,dp[n+1][msk]);
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

const int N=1e5+5, K=8;
int dp[N][1<<K];

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,m,k;
	cin >> n >> m >> k;
	vector<array<int,2>> v(n);
	vector<int> type(n+1);
	rep(i,0,n)cin >> v[i][0] >> v[i][1];
	sort(all(v));
	v.push_back(array<int,2>({m+1,m+1}));
	int taken[K] = {};
	rep(i,0,n){
		rep(j,0,k){
			if(taken[j] <= v[i][0]){
				taken[j] = v[i][1] + 1;
				type[i] = j;
				break;
			}
		}
	}
	int d[K] = {};
	int cur = 1;
	rep(i,0,n+1){
		int curx = cur;
		rep(msk,0,1 << k){
			int on = __builtin_popcount(msk) % 2;
			bool val = 1;
			rep(j,0,k)if(((msk >> j)&1) && d[j] == 0)val = 0;
			if(!val)continue;

			// take
			vector<int> tmp;
			int nxt = msk;
			rep(j,0,k){
				if(d[j] < v[i][0]){
					tmp.push_back(d[j]);
				 	nxt ^= 1 << j;
				}
			}
			tmp.push_back(cur);
			tmp.push_back(v[i][0]);
			sort(all(tmp));
			int add = 0;
			rep(j,0,tmp.size()-1){
				add += on * (tmp[j+1] - tmp[j]);
				on ^= 1;
			}
			gmax(dp[i+1][nxt],dp[i][msk] + add);
		}
		d[type[i]] = v[i][1];
		cur = v[i][0];
	}
	int ans = 0;
	rep(msk,0, 1<< k){
		gmax(ans,dp[n+1][msk]);
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

struct e{
	int x, bal, ind;
	e(int x, int bal, int ind) : x(x), bal(bal), ind(ind){};
};

bool operator< (const e a, const e b){
	return a.x < b.x || (a.x == b.x && a.bal < b.bal);
}

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<e> v;
    for(int i = 0; i < n; ++i){
        int l, r;
        cin >> l >> r;
        v.push_back(e(l, 1, i));
        v.push_back(e(r + 1, -1, i));
    }
    vector<vector<int>> dp(2 * n, vector<int>(257, 0));
    sort(v.begin(), v.end());
    vector<int> masks;
    masks.push_back(0);
    vector<int> ord_by_ind(2*n, 0);
    set<int> bits;
    for(int i = 0; i < 8; ++i) bits.insert(i);
    for(int i = 0; i < v.size(); ++i){
        if(v[i].bal == 1){
            int bit = *bits.begin();
            bits.erase(bits.begin());
            int ms = masks.size();
            for(int j = 0; j < ms; ++j){
                if(i != 0){
                    dp[i][masks[j]] = dp[i - 1][masks[j]] + (__builtin_popcount(masks[j]) % 2) * (v[i].x - v[i - 1].x);
                    dp[i][masks[j] + (1 << bit)] = dp[i - 1][masks[j]] + (__builtin_popcount(masks[j]) % 2) * (v[i].x - v[i - 1].x);
                }
                masks.push_back(masks[j] + (1 << bit));
            }
            ord_by_ind[v[i].ind] = bit;
        } else {
            int bt = ord_by_ind[v[i].ind];
            bits.insert(bt);
            for(int j = 0; j < masks.size(); ++j){
                if(((masks[j] >> bt) & 1) == 1){
                    dp[i][masks[j] - (1 << bt)] = max(dp[i - 1][masks[j]] + (__builtin_popcount(masks[j]) % 2) * (v[i].x - v[i - 1].x), dp[i][masks[j] - (1 << bt)]);
                    masks[j] -= (1 << bt);
                } else {
                    dp[i][masks[j]] = max(dp[i - 1][masks[j]] + (__builtin_popcount(masks[j]) % 2) * (v[i].x - v[i - 1].x), dp[i][masks[j]]);
                }
            }
            set<int> tmp(masks.begin(), masks.end());
            masks = vector<int>(tmp.begin(), tmp.end());
        }
        //for(int m : masks) cout << m << ' '; cout << endl;

    }
    cout << dp[2 * n - 1][0];

}


       #include <bits/stdc++.h>

       using namespace std;

       struct e{
       	int x, bal, ind;
       	e(int x, int bal, int ind) : x(x), bal(bal), ind(ind){};
       };

       bool operator< (const e a, const e b){
       	return a.x < b.x || (a.x == b.x && a.bal < b.bal);
       }

       int main(){
           int n, m, k;
           cin >> n >> m >> k;
           vector<e> v;
           for(int i = 0; i < n; ++i){
               int l, r;
               cin >> l >> r;
               v.push_back(e(l, 1, i));
               v.push_back(e(r + 1, -1, i));
           }
           vector<vector<int>> dp(2 * n, vector<int>(257, 0));
           sort(v.begin(), v.end());
           vector<int> masks;
           masks.push_back(0);
           vector<int> ord_by_ind(2*n, 0);
           set<int> bits;
           for(int i = 0; i < 8; ++i) bits.insert(i);
           for(int i = 0; i < v.size(); ++i){
               if(v[i].bal == 1){
                   int bit = *bits.begin();
                   bits.erase(bits.begin());
                   int ms = masks.size();
                   for(int j = 0; j < ms; ++j){
                       if(i != 0){
                           dp[i][masks[j]] = dp[i - 1][masks[j]] + (__builtin_popcount(masks[j]) % 2) * (v[i].x - v[i - 1].x);
                           dp[i][masks[j] + (1 << bit)] = dp[i - 1][masks[j]] + (__builtin_popcount(masks[j]) % 2) * (v[i].x - v[i - 1].x);
                       }
                       masks.push_back(masks[j] + (1 << bit));
                   }
                   ord_by_ind[v[i].ind] = bit;
               } else {
                   int bt = ord_by_ind[v[i].ind];
                   bits.insert(bt);
                   for(int j = 0; j < masks.size(); ++j){
                       if(((masks[j] >> bt) & 1) == 1){
                           dp[i][masks[j] - (1 << bt)] = max(dp[i - 1][masks[j]] + (__builtin_popcount(masks[j]) % 2) * (v[i].x - v[i - 1].x), dp[i][masks[j] - (1 << bt)]);
                           masks[j] -= (1 << bt);
                       } else {
                           dp[i][masks[j]] = max(dp[i - 1][masks[j]] + (__builtin_popcount(masks[j]) % 2) * (v[i].x - v[i - 1].x), dp[i][masks[j]]);
                       }
                   }

               }
               //for(int m : masks) cout << m << ' '; cout << endl;

           }
           cout << dp[2 * n - 1][0];

       }


#include<map>
#include<list>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define il inline
#define ll long long
#define rl register ll
#define ri register int
#define rc register char
using namespace std;
il int read(){
	rc c=' ';
	ri v=0,x=1;
	while((c<'0')||(c>'9')){if(c=='-') x=-1;c=getchar();}
	while((c>='0')&&(c<='9')){v=(v<<1)+(v<<3)+(c^48);c=getchar();}
	return v*x;
}
il void write(ri x){
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10^48);
}
const int N=2e5+10,M=260;
vector<int> seg[N];
int n,m,k,cnt,ans,l[N],r[N],pt[N],st[M],dp[N][M];
il int count(ri x){
	ri res=0;
	while(x) res+=(x&1),x>>=1;
	return res;
}
int main(){
	n=read(),m=read(),k=read();
	for(ri i=1;i<=n;i++){
		l[i]=read(),pt[++cnt]=l[i];
		r[i]=read()+1,pt[++cnt]=r[i];
	}
	sort(pt+1,pt+cnt+1);
	cnt=unique(pt+1,pt+cnt+1)-pt-1;
	for(ri i=1;i<=n;i++){
		l[i]=lower_bound(pt+1,pt+cnt+1,l[i])-pt;
		r[i]=lower_bound(pt+1,pt+cnt+1,r[i])-pt;
		for(ri j=l[i];j<r[i];j++)
			seg[j].push_back(i);
	}
	for(ri i=1;i<cnt;i++){
		vector<int> pre,now;
		memset(st,0,sizeof(st));
		ri len=pt[i+1]-pt[i];
		for(ri j=0;j<(int)seg[i-1].size();j++)
			for(ri k=0;k<(int)seg[i].size();k++)
				if(seg[i-1][j]==seg[i][k]){
					pre.push_back(j);
					now.push_back(k);
				}
		ri pst=1<<(int)seg[i-1].size();
		ri nst=1<<(int)seg[i].size();
		for(ri j=0;j<pst;j++){
            ri status=0;
            for(ri k=0;k<(int)pre.size();k++)
                status|=(j>>pre[k]&1)<<k;
            st[status]=max(st[status],dp[i-1][j]);
        }
		for(ri j=0;j<nst;j++){
            ri status=0;
            for(ri k=0;k<(int)now.size();k++)
                status|=(j>>now[k]&1)<<k;
			dp[i][j]=max(dp[i][j],st[status]+(count(j)&1)*len);
            ans=max(dp[i][j],ans);
        }
	}
	write(ans);
	return ~~(0-0);
}


#include<map>
#include<list>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define il inline
#define ll long long
#define rl register ll
#define ri register int
#define rc register char
using namespace std;
il int read(){
	rc c=' ';
	ri v=0,x=1;
	while((c<'0')||(c>'9')){if(c=='-') x=-1;c=getchar();}
	while((c>='0')&&(c<='9')){v=(v<<1)+(v<<3)+(c^48);c=getchar();}
	return v*x;
}
il void write(ri x){
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10^48);
}
const int N=2e5+10,M=260;
vector<int> seg[N];
int n,m,k,cnt,ans,l[N],r[N],pt[N],st[M],dp[N][M];
il int count(ri x){
	ri res=0;
	while(x) res+=(x&1),x>>=1;
	return res;
}
int main(){
	n=read(),m=read(),k=read();
	for(ri i=1;i<=n;i++){
		l[i]=read(),pt[++cnt]=l[i];
		r[i]=read()+1,pt[++cnt]=r[i];
	}
	sort(pt+1,pt+cnt+1);
	cnt=unique(pt+1,pt+cnt+1)-pt-1;
	for(ri i=1;i<=n;i++){
		l[i]=lower_bound(pt+1,pt+cnt+1,l[i])-pt;
		r[i]=lower_bound(pt+1,pt+cnt+1,r[i])-pt;
		for(ri j=l[i];j<r[i];j++)
			seg[j].push_back(i);
	}
	for(ri i=1;i<cnt;i++){
		vector<int> pre,now;
		memset(st,0,sizeof(st));
		ri len=pt[i+1]-pt[i];
		for(ri j=0;j<(int)seg[i-1].size();j++)
			for(ri k=0;k<(int)seg[i].size();k++)
				if(seg[i-1][j]==seg[i][k]){
					pre.push_back(j);
					now.push_back(k);
				}
		ri pst=1<<(int)seg[i-1].size();
		ri nst=1<<(int)seg[i].size();
		for(ri j=0;j<pst;j++){
            ri status=0;
            for(ri k=0;k<(int)pre.size();k++)
                status|=(j>>pre[k]&1)<<k;
            st[status]=max(st[status],dp[i-1][j]);
        }
		for(ri j=0;j<nst;j++){
            ri status=0;
            for(ri k=0;k<(int)pre.size();k++)
                status|=(j>>pre[k]&1)<<k;
			dp[i][j]=max(dp[i][j],st[status]+(count(j)&1)*len);
            ans=max(dp[i][j],ans);
        }
	}
	write(ans);
	return ~~(0-0);
}


#include<map>
#include<list>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define il inline
#define ll long long
#define rl register ll
#define ri register int
#define rc register char
using namespace std;
il int read(){
	rc c=' ';
	ri v=0,x=1;
	while((c<'0')||(c>'9')){if(c=='-') x=-1;c=getchar();}
	while((c>='0')&&(c<='9')){v=(v<<1)+(v<<3)+(c^48);c=getchar();}
	return v*x;
}
il void write(ri x){
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10^48);
}
const int N=2e5+10,M=260;
vector<int> seg[N];
int n,m,k,cnt,ans,l[N],r[N],pt[N],st[M],dp[N][M];
il int count(ri x){
	ri res=0;
	while(x) res+=(x&1),x>>=1;
	return res;
}
int main(){
	n=read(),m=read(),k=read();
	for(ri i=1;i<=n;i++){
		l[i]=read(),pt[++cnt]=l[i];
		r[i]=read()+1,pt[++cnt]=r[i];
	}
	sort(pt+1,pt+cnt+1);
	cnt=unique(pt+1,pt+cnt+1)-pt-1;
	for(ri i=1;i<=n;i++){
		l[i]=lower_bound(pt+1,pt+cnt+1,l[i])-pt;
		r[i]=lower_bound(pt+1,pt+cnt+1,r[i])-pt;
		for(ri j=l[i];j<r[i];j++)
			seg[j].push_back(i);
	}
	for(ri i=1;i<cnt;i++){
		vector<int> pre,now;
		memset(st,0,sizeof(st));
		ri len=pt[i+1]-pt[i];
		for(ri j=0;j<(int)seg[i-1].size();j++)
			for(ri k=0;k<(int)seg[i].size();k++)
				if(seg[i-1][j]==seg[i][k]){
					pre.push_back(j);
					now.push_back(k);
				}
		ri pst=1<<(int)pre.size();
		ri nst=1<<(int)now.size();
		for(ri j=0;j<pst;j++){
            ri status=0;
            for(ri k=0;k<(int)pre.size();k++)
                status|=(j>>pre[k]&1)<<k;
            st[status]=max(st[status],dp[i-1][j]);
        }
		for(ri j=0;j<nst;j++){
            ri status=0;
            for(ri k=0;k<(int)pre.size();k++)
                status|=(j>>pre[k]&1)<<k;
			dp[i][j]=max(dp[i][j],st[status]+(count(j)&1)*len);
            ans=max(dp[i][j],ans);
        }
	}
	write(ans);
	return ~~(0-0);
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5, M = 1e9 + 5, K = 10, INF = 0x3f3f3f3f;
int n, m, k, dp[1 << K], nowEvent[K];
struct EVENT {
	int pos, id;
	EVENT() : pos(0), id(0) {}
	EVENT(int _p, int _i) : pos(_p), id(_i) {}
	bool operator < (const EVENT &d) const { return pos < d.pos; }
};
vector<EVENT> event;
int Count(int num) {
	int ret = 0;
	for (int i = 0; i < 8; ++i) ret += (num >> i) & 1;
	return ret;
}
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; ++i) {
		int L, R;
		scanf("%d%d", &L, &R);
		event.push_back(EVENT(L, i));
		event.push_back(EVENT(R + 1, -i));
		//这里应该写成 -i...过脑子！！！
	}
	sort(event.begin(), event.end());
	for (int i = 1; i < 256; ++i) dp[i] = -INF;
	for (int i = 0; i < event.size(); ++i) {
		int id = event[i].id, len = (i == event.size() - 1) ? 0 : (event[i + 1].pos - event[i].pos);
//		printf("id : %d\n", id);
		if (id > 0) {
			int pos = 0;
			for (int j = 0; j < 8; ++j) {
				if (nowEvent[j] == 0) {
					nowEvent[j] = id;
					pos = j;
					break ;
				}
			}
			for (int st = 255; st >= 0; --st) {
				if (st & (1 << pos)) dp[st] = dp[st ^ (1 << pos)] + len * (Count(st) & 1);
				else dp[st] = dp[st] + len * (Count(st) & 1);
			}
		} else {
			int pos = 0;
			for (int j = 0; j < 8; ++j) {
				if (nowEvent[j] == -id) {
					nowEvent[j] = 0;
					pos = j;
					break ;
				}
			}
//			printf("pos : %d\n", pos);
			for (int st = 0; st < 256; ++st) { //这里应该是从0到 (1<<k)-1
				if (st & (1 << pos)) dp[st] = -INF;
				else dp[st] = max(dp[st], dp[st ^ (1 << pos)]) + len * (Count(st) & 1);
			}
		}
//		printf("i : %d len : %d\n", i, len);
	//	for (int j = 0; j < k; ++j) printf("j : %d nowEvent : %d\n", j, nowEvent[j]);
//		for (int st = 0; st < (1 << k); ++st) printf("st : %d dp : %d\n", st, dp[st]);
	//	printf("\n");
	}
	printf("%d\n", dp[0]);
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5, M = 1e9 + 5, K = 8, INF = 0x3f3f3f3f;
int n, m, k, dp[1 << K], nowEvent[K];
struct EVENT {
	int pos, id;
	EVENT() : pos(0), id(0) {}
	EVENT(int _p, int _i) : pos(_p), id(_i) {}
	bool operator < (const EVENT &d) const { return pos < d.pos; }
};
vector<EVENT> event;
int Count(int num) {
	int ret = 0;
	for (int i = 0; i < 8; ++i) ret += (num >> i) & 1;
	return ret;
}
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; ++i) {
		int L, R;
		scanf("%d%d", &L, &R);
		event.push_back(EVENT(L, i));
		event.push_back(EVENT(R + 1, -i));
		//这里应该写成 -i...过脑子！！！
	}
	sort(event.begin(), event.end());
	for (int i = 1; i < 256; ++i) dp[i] = -INF;
	for (int i = 0; i < event.size(); ++i) {
		int id = event[i].id, len = (i == event.size() - 1) ? 0 : (event[i + 1].pos - event[i].pos);
//		printf("id : %d\n", id);
		if (id > 0) {
			int pos = 0;
			for (int j = 0; j < 8; ++j) {
				if (nowEvent[j] == 0) {
					nowEvent[j] = id;
					pos = j;
					break ;
				}
			}
			for (int st = 255; st >= 0; --st) {
				if (st & (1 << pos)) dp[st] = dp[st ^ (1 << pos)] + len * (Count(st) & 1);
				else dp[st] = dp[st] + len * (Count(st) & 1);
			}
		} else {
			int pos = 0;
			for (int j = 0; j < 8; ++j) {
				if (nowEvent[j] == -id) {
					nowEvent[j] = 0;
					pos = j;
					break ;
				}
			}
//			printf("pos : %d\n", pos);
			for (int st = 0; st < 256; ++st) { //这里应该是从0到 (1<<k)-1
				if (st & (1 << pos)) dp[st] = -INF;
				else dp[st] = max(dp[st], dp[st ^ (1 << pos)]) + len * (Count(st) & 1);
			}
		}
//		printf("i : %d len : %d\n", i, len);
	//	for (int j = 0; j < k; ++j) printf("j : %d nowEvent : %d\n", j, nowEvent[j]);
//		for (int st = 0; st < (1 << k); ++st) printf("st : %d dp : %d\n", st, dp[st]);
	//	printf("\n");
	}
	printf("%d\n", dp[0]);
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5, M = 1e9 + 5, K = 10, INF = 0x3f3f3f3f;
int n, m, k, dp[1 << K], nowEvent[K];
struct EVENT {
	int pos, id;
	EVENT() : pos(0), id(0) {}
	EVENT(int _p, int _i) : pos(_p), id(_i) {}
	bool operator < (const EVENT &d) const { return (pos != d.pos) ? pos < d.pos : id < d.id; }
};
vector<EVENT> event;
int Count(int num) {
	int ret = 0;
	for (int i = 0; i < 8; ++i) ret += (num >> i) & 1;
	return ret;
}
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; ++i) {
		int L, R;
		scanf("%d%d", &L, &R);
		event.push_back(EVENT(L, i));
		event.push_back(EVENT(R + 1, -i));
		//这里应该写成 -i...过脑子！！！
	}
	sort(event.begin(), event.end());
	for (int i = 1; i < 256; ++i) dp[i] = -INF;
	for (int i = 0; i < event.size(); ++i) {
		int id = event[i].id, len = (i == event.size() - 1) ? 0 : (event[i + 1].pos - event[i].pos);
//		printf("id : %d\n", id);
		if (id > 0) {
			int pos = 0;
			for (int j = 0; j < 8; ++j) {
				if (nowEvent[j] == 0) {
					nowEvent[j] = id;
					pos = j;
					break ;
				}
			}
			for (int st = 255; st >= 0; --st) {
				if (st & (1 << pos)) dp[st] = dp[st ^ (1 << pos)] + len * (Count(st) & 1);
				else dp[st] = dp[st] + len * (Count(st) & 1);
			}
		} else {
			int pos = 0;
			for (int j = 0; j < 8; ++j) {
				if (nowEvent[j] == -id) {
					nowEvent[j] = 0;
					pos = j;
					break ;
				}
			}
//			printf("pos : %d\n", pos);
			for (int st = 0; st < 256; ++st) { //这里应该是从0到 (1<<k)-1
				if (st & (1 << pos)) dp[st] = -INF;
				else dp[st] = max(dp[st], dp[st ^ (1 << pos)]) + len * (Count(st) & 1);
			}
		}
//		printf("i : %d len : %d\n", i, len);
	//	for (int j = 0; j < k; ++j) printf("j : %d nowEvent : %d\n", j, nowEvent[j]);
//		for (int st = 0; st < (1 << k); ++st) printf("st : %d dp : %d\n", st, dp[st]);
	//	printf("\n");
	}
	printf("%d\n", dp[0]);
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5, M = 1e9 + 5, K = 8, INF = 0x3f3f3f3f;
int n, m, k, dp[1 << K], nowEvent[K];
struct EVENT {
	int pos, id;
	EVENT() : pos(0), id(0) {}
	EVENT(int _p, int _i) : pos(_p), id(_i) {}
	bool operator < (const EVENT &d) const { return pos < d.pos; }
};
vector<EVENT> event;
int Count(int num) {
	int ret = 0;
	for (int i = 0; i < k; ++i) ret += (num >> i) & 1;
	return ret;
}
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; ++i) {
		int L, R;
		scanf("%d%d", &L, &R);
		event.push_back(EVENT(L, i));
		event.push_back(EVENT(R + 1, -i));
		//这里应该写成 -i...过脑子！！！
	}
	sort(event.begin(), event.end());
	for (int i = 1; i < (1 << k); ++i) dp[i] = -INF;
	for (int i = 0; i < event.size(); ++i) {
		int id = event[i].id, len = (i == event.size() - 1) ? 0 : (event[i + 1].pos - event[i].pos);
//		printf("id : %d\n", id);
		if (id > 0) {
			int pos = 0;
			for (int j = 0; j < k; ++j) {
				if (nowEvent[j] == 0) {
					nowEvent[j] = id;
					pos = j;
					break ;
				}
			}
			for (int st = (1 << k) - 1; st >= 0; --st) {
				if (st & (1 << pos)) dp[st] = dp[st ^ (1 << pos)] + len * (Count(st) & 1);
				else dp[st] = dp[st] + len * (Count(st) & 1);
			}
		} else {
			int pos = 0;
			for (int j = 0; j < k; ++j) {
				if (nowEvent[j] == -id) {
					nowEvent[j] = 0;
					pos = j;
					break ;
				}
			}
//			printf("pos : %d\n", pos);
			for (int st = 0; st < (1 << k); ++st) {
				if (st & (1 << pos)) dp[st] = -INF;
				else dp[st] = max(dp[st], dp[st ^ (1 << pos)]) + len * (Count(st) & 1);
			}
		}
//		printf("i : %d len : %d\n", i, len);
	//	for (int j = 0; j < k; ++j) printf("j : %d nowEvent : %d\n", j, nowEvent[j]);
//		for (int st = 0; st < (1 << k); ++st) printf("st : %d dp : %d\n", st, dp[st]);
	//	printf("\n");
	}
	printf("%d\n", dp[0]);
	return 0;
}


#include <bits/stdc++.h>
#define re register int
#define il inline
#define ll long long
using namespace std;
const int inf=1e9;
il int read(){
	char c=getchar();int z=0,f=1;
	while(c!='-'&&(c>'9'||c<'0')) c=getchar();
	if(c=='-') f=-1,c=getchar();
	while(c>='0'&&c<='9') z=(z<<1)+(z<<3)+c-'0',c=getchar();
	return z*f;
}
int n,f[1055],vis[305];
vector<pair<int,int> > v;
int main (){
	n=read();read();read();
	for(re i=1,l,r;i<=n;i++){
		l=read(),r=read();
		v.push_back({l,i});
		v.push_back({r+1,-i});
	}
	sort(v.begin(),v.end());
	for(re i=1;i<256;i++) f[i]=-inf;
	for(re x=0;x<v.size();x++){
		int id=v[x].second,k;
	 	int len = x == v.size() - 1 ? 0 : v[x + 1].first - v[x].first;
		if(id>0){
			for(re i=0;i<8;i++)
				if(vis[i]==0) {
					vis[k=i]=id;
					break;
				}
			for(re i=255;i>=0;i--)
				if(i>>k&1) f[i]=f[i^1<<k]+len*__builtin_parity(i);
				else f[i]=f[i]+len*__builtin_parity(i);
		}
		else {
			for(re i=0;i<8;i++)
				if(vis[i]==-id){
					vis[k=i]=0;
					break;
				}
			for(re i=0;i<256;i++){
				if(i>> k & 1) f[i]=-inf;
				else  f[i]=max(f[i],f[i^1<<k])+len*__builtin_parity(i);
			}
		}
	}
	cout<<f[0];
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long int64;

int main()
{
	ios::sync_with_stdio(0), cin.tie(0);

	int allMagic = 0, m = 0, limit = 0, newMagic = 0;
	cin >> allMagic >> m >> limit;
	struct Magic
	{
		int l, r;
		bool operator < (const Magic& a) const
		{
			if (l != a.l)
				return l < a.l;
			return r < a.r;
		}
	} magic[allMagic + 1];

	vector <int> number;
	vector <int> dp(1 << limit | 1);
	vector <int> maxValue(1 << limit | 1);
	vector <int> numberSize(allMagic + 1);
	vector <int> magicCovered(allMagic * 5 + 1);
	vector <int> magicEnd(allMagic * 5 + 1);
	vector <vector <bool>> isMagicCovered(allMagic * 5 + 1);
	vector <vector <bool>> isMagicEnd(allMagic * 5 + 1);
	vector <bool> isUseed(allMagic + 1);

	function <void()> init = [&]()
	{
		number.push_back(0);
		for (int i = 1; i <= allMagic; ++i)
		{
			cin >> magic[i].l >> magic[i].r;
			number.push_back(magic[i].l);
			number.push_back(magic[i].r);
			number.push_back(max(magic[i].l - 1, 1));
		}
		sort(number.begin(), number.end());
		newMagic = unique(number.begin() + 1, number.end()) - number.begin() - 1;
//		cerr << newMagic << '\n';
//		cout << number[newMagic] << '\n';
//		for (int g : number)
//			cout << g << '\n';
		numberSize.resize(number.size() + 3);
		for (int i = 1; i <= allMagic; ++i)
		{
			magic[i].l = lower_bound(number.begin() + 1, number.begin() + newMagic, magic[i].l) - number.begin() ;
			magic[i].r = lower_bound(number.begin() + 1, number.begin() + newMagic, magic[i].r) - number.begin() ;
//			cerr << magic.magicL[i] << " " << magic[i].r[i] << '\n';
		}
		sort(magic + 1, magic + 1 + allMagic);
		for (int i = 1;i <= newMagic; ++i)
		{
			numberSize[i] = number[i] - number[i - 1];
			assert(numberSize[i] > 0);
//			cout <<
//			cout << numberSize[i] << '\n';
		}
	};

	function <int(int)> count = [&](int s)
	{
		int RES = 0;
		while (s > 0)
			RES ^= 1, s -= s & -s;
		return RES;
	};

	function <void()> solve = [&]()
	{
		for (int i = 1;i <= newMagic; ++i)
			isMagicCovered[i].resize(limit + 1),
			isMagicEnd[i].resize(limit + 1);

		for (int i = 1; i <= limit; ++i)
		{
			int lowest = 0;
			for (int j = 1; j <= allMagic; ++j)
			{
				if (isUseed[j] || lowest >= magic[j].l)
					continue;
				isUseed[j] = 1;
//				cout << j << '\n';
				for (int k = magic[j].l; k <= magic[j].r; ++k)
					isMagicCovered[k][i] = 1;

				isMagicEnd[magic[j].r][i] = 1;
				lowest = magic[j].r;
			}
		}

		for (int i = 1; i <= newMagic; ++i)
		{
			for (int j = 1;j <= limit; ++j)
				magicCovered[i] |= (1 << j - 1) * int(isMagicCovered[i][j]),
				magicEnd[i] |= (1 << j - 1) * int(isMagicEnd[i][j]);
//			cout << magicCovered[i] << " " << magicEnd[i] << '\n';
		}

		int allBitMakes = 1 << limit;
		vector <int> f(allBitMakes + 1, 0);
		for (int i = 1; i < allBitMakes; ++i)
			f[i] = count(i);
		//	cout << f[i] << '\n';

		for (int i = 1; i <= newMagic; ++i)
		{
			for (int s = 0; s < allBitMakes; ++s)
			{
				if ((s | magicCovered[i]) != magicCovered[i])
					continue; dp[s] = 0;
				int basic = (s & magicCovered[i - 1]) & (magicCovered[i - 1] ^ magicEnd[i - 1]);
				for (int k = magicEnd[i - 1]; k; k = (k - 1) & magicEnd[i - 1])
					dp[s] = max(dp[s], maxValue[basic | k] + f[s] * numberSize[i]);

				dp[s] = max(dp[s], maxValue[basic] + f[s] * numberSize[i]);
//				cout << dp[s] << " " << numberSize[i] << '\n';
			}

			maxValue = dp;
		}

//		cout << number.size() << '\n';

		cout << *max_element(maxValue.begin(), maxValue.end()) << '\n';
	};

	init();
	solve();

	return 0;
}


#include <iostream>
#include <algorithm>

#define lowbit(x) ((x) & -(x))
#define max_3(a, b, c) max(a, std::max(b, c))

const int N = 200000 + 7, S = 1 << 8 | 7;

int n, m, k;
struct str {
	int x, y;
} a[N];
int b[N];
int e[N], l[N], r[N], z[N];
int f[S], g[S];

int main() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d%d", &a[i].x, &a[i].y), e[i] = --a[i].x, e[i + n] = a[i].y;
	std::sort(e + 1, e + n * 2 + 1);
	m = std::unique(e + 1, e + n * 2 + 1) - e - 1;
	for (int i = 1; i <= n; ++i)
		a[i].x = std::lower_bound(e + 1, e + m + 1, a[i].x) - e,
		a[i].y = std::lower_bound(e + 1, e + m + 1, a[i].y) - e;

	std::sort(a + 1, a + n + 1, [](str a, str b) {
		return a.x != b.x ? a.x < b.x : a.y < b.y;
	});
	for (int j = 1; j <= k; ++j)
		for (int i = 1, l = 0; i <= n; ++i)
			if (!b[i] && l <= a[i].x) b[i] = j, l = a[i].y;

	const int A = (1 << k) - 1;
	for (int i = 1; i <= n; ++i)
		l[a[i].x] |= 1 << b[i] - 1, r[a[i].y] |= 1 << b[i] - 1;
	for (int i = 1; i <= m; ++i)
		z[i] = z[i - 1] ^ r[i] | l[i];
	for (int i = 1; i <= m; ++i) {
		std::fill(g, g + A + 1, 0);
		for (int j = A, l, u, v; ~j; --j)
			l = j & ~r[i], u = lowbit(l), v = lowbit(l ^ u),
			g[j] = std::max_3(f[j], g[j ^ u], g[j ^ v]);
		std::fill(f, f + A + 1, 0);
		for (int j = 0; j <= A; ++j)
			if ((z[i] & j) == j)
				f[j] = g[j & ~l[i] & ~r[i]] + __builtin_parity(j) * (e[i + 1] - e[i]);
	}
	printf("%d", f[0]);

	return 0;
}


//Coded by tzc_wk
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int n=read(),m=read(),k=read(),dp[2][1<<10],ind[15];
int is[1<<8];
pair<int,int> a[1000005];
signed main(){
	fz(i,0,n-1){
		a[i].fi=read();a[i+n].fi=read();a[i].fi--;
		a[i].se=i;a[i+n].se=i+n;
	}
	sort(a,a+(n<<1));
	int sz=0;
	for(int i=0;i<1<<8;i++)	is[i]=__builtin_parity(i);
	fz(i,0,n*2-1){
		memset(dp[(i&1)^1],0,sizeof(dp[(i&1)^1]));
//		cout<<a[i].fi<<" "<<a[i].se<<endl;
		if(a[i].se<n){
			for(int j=0;j<(1<<sz);j++){
				int extra=0;
				if(i)	extra=(a[i].fi-a[i-1].fi)*is[j];
				dp[(i&1)^1][j|(1<<sz)]=max(dp[(i&1)^1][j|(1<<sz)],dp[i&1][j]+extra);
				dp[(i&1)^1][j]=max(dp[(i&1)^1][j],dp[i&1][j]+extra);
			}
			ind[sz++]=a[i].second;
		}
		else{
			a[i].se-=n;
			int k=find(ind,ind+sz,a[i].se)-ind;
			int sub=(1<<k)-1;
			for(int j=0;j<(1<<sz);j++){
				int extra=0;
				if(i)	extra=(a[i].fi-a[i-1].fi)*is[j];
				dp[(i&1)^1][(j&sub)|((j>>1)&(~sub))]=max(dp[(i&1)^1][(j&sub)|((j>>1)&(~sub))],dp[i&1][j]+extra);
			}
			for(int j=k+1;j<sz;j++)	ind[j-1]=ind[j];
			ind[--sz]=0;
		}
	}
	cout<<dp[0][0]<<endl;
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <ctype.h>
const int bufSize = 1e6;
#define DEBUG
inline char nc()
{
    #ifdef DEBUG
    return getchar();
    #endif
    static char buf[bufSize], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2) ? EOF : *p1++;
}
template<typename T>
inline T read(T &r)
{
    static char c;
    static int flag;
    flag = 1, r = 0;
    for (c = nc(); !isdigit(c); c = nc()) if (c == '-') flag = -1;
    for (; isdigit(c); c = nc()) r = r * 10 + c - 48;
    return r *= flag;
}
const int maxn = 3e5 + 100;
const int inf = 1 << 30;
int n, m, up, cnt;
struct node
{
    int pos, id;
} A[maxn << 1];
inline bool cmp(const node& a, const node& b) { return a.pos != b.pos ? a.pos < b.pos : a.id < b.id; }
int f[1 << 9], popc[1 << 9];
int vis[15];
int main()
{
    read(n), read(m), read(up);
    for (int i = 1, l, r; i <= n; ++i) read(l), read(r), A[++cnt].pos = l, A[cnt].id = i, A[++cnt].pos = r + 1, A[cnt].id = -i;
    std::sort(A + 1, A + 1 + cnt, cmp);
    for (int i = 1; i < (1 << up); ++i) f[i] = -inf, popc[i] = popc[i >> 1] ^ (i & 1);
    for (int i = 1; i < cnt; ++i)
    {
        int len = A[i + 1].pos - A[i].pos, k;
        if (A[i].id > 0)
        {
            for (int j = 0; j < 8; ++j) if (!vis[j]) { vis[j] = A[i].id, k = j; break; }
            for (int j = (1 << up) - 1; j >= 0; --j)
                if (j & (1 << k)) f[j] = f[j ^ (1 << k)] + len * popc[j]; else f[j] = f[j] + len * popc[j];
        }
        else
        {
            for (int j = 0; j < 8; ++j) if (vis[j] == -A[i].id) { vis[j] = 0, k = j; break; }
            for (int j = 0; j < (1 << up); ++j)
                if (j & (1 << k)) f[j] = -inf;
                else f[j] = std::max(f[j], f[j ^ (1 << k)]) + len * popc[j];
        }
    }
    int res = 0;
    for (int i = 0; i < (1 << up); ++i) res = std::max(res, f[i]);
    printf("%d\n", res);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+23;

int dp[maxn<<1][1<<9];

int n,m,k,cnt;
int l[maxn],r[maxn],t[maxn<<1];
int to[9];
vector<int> g[maxn<<1];
int main(){
    #ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
    #endif // ONLINE_JUDGE
    cin>>n>>m>>k;
    for(int i=0;i<n;i++){
        scanf("%d%d",&l[i],&r[i]);
        t[cnt++]=l[i];
        t[cnt++]=r[i]+1;
    }
    //for(int i=0;i<cnt;i++) printf("%d ",t[i]);puts("");
    sort(t,t+cnt);cnt=unique(t,t+cnt)-t;
    for(int i=0;i<n;i++){
        l[i]=lower_bound(t,t+cnt,l[i])-t;
        r[i]=lower_bound(t,t+cnt,r[i]+1)-t;
        for(int j=l[i];j<r[i];j++) g[j].push_back(i);
    }
    int num=t[1]-t[0];
    for(int i=0;i<1<<g[0].size();i++){
        dp[0][i]=__builtin_popcount(i)%2?num:0;
    }
    for(int i=1;i<cnt-1;i++){
        memset(to,-1,sizeof(to));
        int num=t[i+1]-t[i],base=0;
        for(int j=0;j<(int)g[i].size();j++){
            for(int k=0;k<(int)g[i-1].size();k++){
                if(g[i][j]==g[i-1][k]) to[k]=j,base|=1<<j;
            }
        }
        for(int j=0;j<1<<g[i-1].size();j++){
            int mask=0,mask1=0;
            for(int k=0;k<8;k++){
                if((j&(1<<k)) && (to[k]!=-1)) mask|=1<<k,mask1|=1<<to[k];
            }
            dp[i][mask1]=max(dp[i][mask1],dp[i-1][j]);
        }
        for(int j=(1<<g[i].size())-1;j>=0;j--){
            dp[i][j]=dp[i][j&base]+(__builtin_popcount(j)%2?num:0);
        }
        /*
        printf("base: %d\n",base);
        for(int j=0;j<1<<3;j++) printf("%d ",dp[i][j]);puts("");
        */
    }
    cout<<*max_element(dp[cnt-2],dp[cnt-2]+(1<<9));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+23;

int dp[maxn<<1][1<<9];

int n,m,k,cnt;
int l[maxn],r[maxn],t[maxn<<1];
int to[9];
vector<int> g[maxn];
int main(){
    #ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
    #endif // ONLINE_JUDGE
    cin>>n>>m>>k;
    for(int i=0;i<n;i++){
        scanf("%d%d",&l[i],&r[i]);
        t[cnt++]=l[i];
        t[cnt++]=r[i]+1;
    }
    //for(int i=0;i<cnt;i++) printf("%d ",t[i]);puts("");
    sort(t,t+cnt);cnt=unique(t,t+cnt)-t;
    for(int i=0;i<n;i++){
        l[i]=lower_bound(t,t+cnt,l[i])-t;
        r[i]=lower_bound(t,t+cnt,r[i]+1)-t;
        for(int j=l[i];j<r[i];j++) g[j].push_back(i);
    }
    int num=t[1]-t[0];
    for(int i=0;i<1<<g[0].size();i++){
        dp[0][i]=__builtin_popcount(i)%2?num:0;
    }
    for(int i=1;i<cnt-1;i++){
        memset(to,-1,sizeof(to));
        int num=t[i+1]-t[i],base=0;
        for(int j=0;j<(int)g[i].size();j++){
            for(int k=0;k<(int)g[i-1].size();k++){
                if(g[i][j]==g[i-1][k]) to[k]=j,base|=1<<j;
            }
        }
        for(int j=0;j<1<<g[i-1].size();j++){
            int mask=0,mask1=0;
            for(int k=0;k<8;k++){
                if((j&(1<<k)) && (to[k]!=-1)) mask|=1<<k,mask1|=1<<to[k];
            }
            dp[i][mask1]=max(dp[i][mask1],dp[i-1][j]);
        }
        for(int j=(1<<g[i].size())-1;j>=0;j--){
            dp[i][j]=dp[i][j&base]+(__builtin_popcount(j)%2?num:0);
        }
        /*
        printf("base: %d\n",base);
        for(int j=0;j<1<<3;j++) printf("%d ",dp[i][j]);puts("");
        */
    }
    cout<<*max_element(dp[cnt-2],dp[cnt-2]+(1<<9));
    return 0;
}


#include <iostream>
#include <algorithm>

#define lowbit(x) ((x) & -(x))
#define max_3(a, b, c) max(a, std::max(b, c))

const int N = 200000 + 7, S = 1 << 8 | 7;

int n, m, k;
struct str {
	int x, y;
} a[N];
int b[N];
int e[N], l[N], r[N], z[N];
int f[S], g[S];

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d%d", &a[i].x, &a[i].y), e[i] = --a[i].x, e[i + n] = a[i].y;
	std::sort(e + 1, e + n * 2 + 1);
	m = std::unique(e + 1, e + n * 2 + 1) - e - 1;
	for (int i = 1; i <= n; ++i)
		a[i].x = std::lower_bound(e + 1, e + m + 1, a[i].x) - e,
		a[i].y = std::lower_bound(e + 1, e + m + 1, a[i].y) - e;

	std::sort(a + 1, a + n + 1, [](str a, str b) {
		return a.x != b.x ? a.x < b.x : a.y < b.y;
	});
	for (int j = 1; j <= k; ++j)
		for (int i = 1, l = 0; i <= n; ++i)
			if (!b[i] && l <= a[i].x) b[i] = j, l = a[i].y;

	for (int i = 1; i <= n; ++i)
		l[a[i].x] |= 1 << b[i] - 1, r[a[i].y] |= 1 << b[i] - 1;
	for (int i = 1; i <= m; ++i)
		z[i] = z[i - 1] ^ r[i] ^ l[i];
	for (int i = 1; i <= m; ++i) {
		std::fill(g, g + (1 << k), 0);
		for (int j = (1 << k) - 1, l, u, v; ~j; --j) {
			g[j] = f[j];
			for (int l = r[i] & ~j; l; l ^= lowbit(l))
				g[j] = std::max(g[j], g[j ^ lowbit(l)]);
		}
		std::fill(f, f + (1 << k), 0);
		for (int j = 0; j < 1 << k; ++j)
			if ((z[i] & j) == j)
				f[j] = g[j & ~l[i]] + __builtin_parity(j) * (e[i + 1] - e[i]);
	}
	printf("%d", f[0]);

	return 0;
}


#include <iostream>
#include <algorithm>

#define popcnt __builtin_popcount
#define lowbit(x) ((x) & -(x))
#define max_3(a, b, c) max(a, std::max(b, c))

const int N = 200000 + 7, S = 1 << 8 | 7;

int n, m, k;
struct str {
	int x, y;
} a[N];
int b[N];
int e[N], l[N], r[N], z[N];
int f[S], g[S];

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d%d%d", &n, &m, &k), ++m;
	for (int i = 1; i <= n; ++i)
		scanf("%d%d", &a[i].x, &a[i].y), e[i] = a[i].x, e[i + n] = ++a[i].y;
	std::sort(e + 1, e + n * 2 + 1);
	m = std::unique(e + 1, e + n * 2 + 1) - e - 1;
	for (int i = 1; i <= n; ++i)
		a[i].x = std::lower_bound(e + 1, e + m + 1, a[i].x) - e,
		a[i].y = std::lower_bound(e + 1, e + m + 1, a[i].y) - e;

	std::sort(a + 1, a + n + 1, [](str a, str b) {
		return a.x != b.x ? a.x < b.x : a.y < b.y;
	});
	for (int j = 1; j <= k; ++j)
		for (int i = 1, l = 0; i <= n; ++i)
			if (!b[i] && l <= a[i].x) b[i] = j, l = a[i].y;

	const int A = (1 << k) - 1;
	for (int i = 1; i <= n; ++i)
		l[a[i].x] |= 1 << b[i] - 1, r[a[i].y] |= 1 << b[i] - 1;
	for (int i = 1; i <= m; ++i)
		z[i] = z[i - 1] ^ r[i] | l[i];
	for (int i = 1; i <= m; ++i) {
		std::fill(g, g + A + 1, 0);
		for (int j = A, l, u, v; ~j; --j)
			l = r[i] ^ (j & r[i]), u = lowbit(l), v = lowbit(l ^ u),
			g[j] = std::max_3(f[j], g[j ^ u], g[j ^ v]);
		std::fill(f, f + A + 1, 0);
		for (int j = 0; j <= A; ++j)
			if ((z[i] & j) == j)
				f[j] = g[j & (A ^ l[i]) & (A ^ r[i])] + (popcnt(j) & 1) * (e[i + 1] - e[i]);
	}
	printf("%d", f[0]);

	return 0;
}


#include <bits/stdc++.h>
#define MAX (ll)(5e5 + 7)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e17)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false);
#define LOG 20

using namespace std;
using ll = long long;
vector<ll> vv[MAX];
ll dp[4][1 << 8];

int main () {
	ll n, m, k, cc = 0;
	cin >> n >> m >> k;
	vector<pair<ll, ll>> vp, el;
	set<ll> se;
	for (ll i = 0; i < n; i++) {
		ll l, r;
		cin >> l >> r;
		vp.push_back (make_pair (l, r));
		se.insert (l);
		se.insert (r);
	}
	sort (vp.begin (), vp.end ());
	for (auto it = se.begin (); ; ) {
		el.push_back (make_pair (*it, *it));
		if (*it != *se.rbegin ()) {
			ll x = *it, y = *(++it);
			if (x + 1 < y) {
				el.push_back (make_pair (x + 1, y - 1));
			}
		}
		else {
			break;
		}
	}
	ll st = 0;
	for (ll i = 0; i < n; i++) {
		while (st < el.size () && el[st].second < vp[i].first) {
			st++;
		}
		for (ll j = st; j < el.size () && el[j].first <= vp[i].second; j++) {
			vv[j].push_back (i);
		}
	}
	ll nn = el.size (), mm = (1 << k), mi = -1, ma = -1, len = 1, mx = 0;
	for (ll i = 0; i < nn; i++) {
		len = ma - mi + 1;
		bool p = (i + 1) & 1, c = i & 1;
		ll d = vv[i].size () ? min (len, vv[i].front () - mi) : len;
		for (ll j = 0; j < mm; j++) {
			dp[3][j >> d] = max (dp[3][j >> d], dp[p][j]);
		}
		for (ll j = 0; j < mm; j++) {
			dp[c][j] = dp[3][j];
			mx = max (dp[c][j], mx);
			dp[3][j] = 0;
		}
		if (vv[i].size () == 0) {
			mi = ma;
			continue;
		}
		mi = vv[i].front ();
		d = vv[i].back () - ma;
		for (ll j = 0; j < (1 << d); j++) {
			bool fl =  __builtin_popcount (j) & 1;
			ll t = ma + 1 - vv[i].front ();
			assert (t >= 0);
			for (ll x = 0; x < (1 << t); x++) {
				ll ind = x | (j << t);
				ll co = (__builtin_popcount (ind) & 1) * (el[i].second - el[i].first + 1);
				dp[3][ind] = max (dp[c][x] + co, dp[3][ind]);
			}
		}
		for (ll j = 0; j < mm; j++) {
			dp[c][j] = dp[3][j];
			mx = max (dp[c][j], mx);
			dp[3][j] = 0;
		}
		mi = vv[i].front (), ma = vv[i].back ();
	}
	cout << mx  << "\n";
}


#include <bits/stdc++.h>
#define MAX (ll)(3e5 + 7)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e17)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false);
#define LOG 20

using namespace std;
using ll = long long;
vector<ll> vv[MAX];
ll dp[MAX][1 << 8];

int main () {
	ll n, m, k, cc = 0;
	cin >> n >> m >> k;
	vector<pair<ll, ll>> vp, el;
	set<ll> se;
	for (ll i = 0; i < n; i++) {
		ll l, r;
		cin >> l >> r;
		vp.push_back (make_pair (l, r));
		se.insert (l);
		se.insert (r);
	}
	sort (vp.begin (), vp.end ());
	for (auto it = se.begin (); ; ) {
		el.push_back (make_pair (*it, *it));
		if (*it != *se.rbegin ()) {
			ll x = *it, y = *(++it);
			if (x + 1 < y) {
				el.push_back (make_pair (x + 1, y - 1));
			}
		}
		else {
			break;
		}
	}
	ll st = 0;
	for (ll i = 0; i < n; i++) {
		while (st < el.size () && el[st].second < vp[i].first) {
			st++;
		}
		for (ll j = st; j < el.size () && el[j].first <= vp[i].second; j++) {
			vv[j].push_back (i);
		}
	}
	ll nn = el.size (), mm = (1 << k), mi = -1, ma = -1, len = 1;
	for (ll i = 0; i < nn; i++) {
		len = ma - mi + 1;
		ll d = vv[i].size () ? min (len, vv[i].front () - mi) : len;
		for (ll j = 0; j < mm; j++) {
			dp[0][j >> d] = max (dp[0][j >> d], dp[i][j]);
		}
		for (ll j = 0; j < mm; j++) {
			dp[i + 1][j] = dp[0][j];
			dp[0][j] = 0;
		}
		if (vv[i].size () == 0) {
			mi = ma;
			continue;
		}
		mi = vv[i].front ();
		d = vv[i].back () - ma;
		for (ll j = 0; j < (1 << d); j++) {
			bool fl =  __builtin_popcount (j) & 1;
			ll t = ma + 1 - vv[i].front ();
			assert (t >= 0);
			for (ll x = 0; x < (1 << t); x++) {
				ll ind = x | (j << t);
				ll co = (__builtin_popcount (ind) & 1) * (el[i].second - el[i].first + 1);
				dp[0][ind] = max (dp[i + 1][x] + co, dp[0][ind]);
			}
		}
		for (ll j = 0; j < mm; j++) {
			dp[i + 1][j] = dp[0][j];
			dp[0][j] = 0;
		}
		mi = vv[i].front (), ma = vv[i].back ();
	}
	ma = 0;
	for (ll i = 0; i < mm; i++) {
		ma = max (dp[nn][i], ma);

	}
	cout << ma  << "\n";
}


#include <bits/stdc++.h>
#define MAX (ll)(5e5 + 7)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e17)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false);
#define LOG 20

using namespace std;
using ll = long long;
int dp[1 << 9], ch[1 << 9], l, pl[MAX];

int main () {
	int n, m, k;
	cin >> n >>  m >> k;
	set<int> se;
	vector<pair<int, int>> vp;
	for (int i = 1; i <= n; i++) {
		int l, r;
		cin >> l >> r;
		vp.push_back (make_pair (l, i));
		vp.push_back (make_pair (r + 1, -i));
	}
	for (int i = 0; i < k; i++) {
		se.insert (i);
	}
	for (int i = 1; i < (1 << k); i++) {
		dp[i] = -MOD, ch[i] = ch[i >> 1] ^ (i & 1);
	}
	sort (vp.begin (), vp.end ());
	for (int i = 0; i < vp.size (); i++) {
		int r = vp[i].first, x = vp[i].second;
		for (int i = 0; i < (1 << k); i++) {
			if (ch[i]) {
				dp[i] += r - l;
			}
		}
		l = r;
		if (x > 0) {
			pl[x] = *se.begin ();
			se.erase (se.begin ());
			for (int i = 0; i < (1 << k); i++) {
				if ((i >> pl[x]) & 1) {
					dp[i] = max (dp[i], dp[i ^ (1 << pl[x])]);
				}
			}
		}
		else {
			x *= -1;
			se.insert (pl[x]);
			for (int i = 0; i < (1 << k); i++) {
				if ((i >> pl[x]) & 1) {
					dp[i ^ (1 << pl[x])] = max (dp[i ^ (1 << pl[x])], dp[i]);
					dp[i] = -MOD;
				}
			}
		}
	}
	cout << dp[0] << "\n";
}


#include <bits/stdc++.h>
#define MAX (ll)(4e5 + 7)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e17)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false);
#define LOG 20

using namespace std;
using ll = long long;
vector<ll> vv[MAX];
ll dp[MAX][1 << 9];

int main () {
	ll n, m, k, cc = 0;
	cin >> n >> m >> k;
	vector<pair<ll, ll>> vp, el;
	set<ll> se;
	for (ll i = 0; i < n; i++) {
		ll l, r;
		cin >> l >> r;
		vp.push_back (make_pair (l, r));
		se.insert (l);
		se.insert (r);
	}
	sort (vp.begin (), vp.end ());
	for (auto it = se.begin (); ; ) {
		el.push_back (make_pair (*it, *it));
		if (*it != *se.rbegin ()) {
			ll x = *it, y = *(++it);
			if (x + 1 < y) {
				el.push_back (make_pair (x + 1, y - 1));
			}
		}
		else {
			break;
		}
	}
	ll st = 0;
	for (ll i = 0; i < n; i++) {
		while (st < el.size () && el[st].second < vp[i].first) {
			st++;
		}
		for (ll j = st; j < el.size () && el[j].first <= vp[i].second; j++) {
			vv[j].push_back (i);
		}
	}
	ll nn = el.size (), mm = (1 << k), mi = -1, ma = -1, len = 1;
	for (ll i = 0; i < nn; i++) {
		len = ma - mi + 1;
		ll d = vv[i].size () ? min (len, vv[i].front () - mi) : len;
		for (ll j = 0; j < mm; j++) {
			dp[0][j >> d] = max (dp[0][j >> d], dp[i][j]);
		}
		for (ll j = 0; j < mm; j++) {
			dp[i + 1][j] = dp[0][j];
			dp[0][j] = 0;
		}
		if (vv[i].size () == 0) {
			mi = ma;
			continue;
		}
		mi = vv[i].front ();
		d = vv[i].back () - ma;
		for (ll j = 0; j < (1 << d); j++) {
			bool fl =  __builtin_popcount (j) & 1;
			ll t = ma + 1 - vv[i].front ();
			assert (t >= 0);
			for (ll x = 0; x < (1 << t); x++) {
				ll ind = x | (j << t);
				ll co = (__builtin_popcount (ind) & 1) * (el[i].second - el[i].first + 1);
				dp[0][ind] = max (dp[i + 1][x] + co, dp[0][ind]);
			}
		}
		for (ll j = 0; j < mm; j++) {
			dp[i + 1][j] = dp[0][j];
			dp[0][j] = 0;
		}
		mi = vv[i].front (), ma = vv[i].back ();
	}
	ma = 0;
	for (ll i = 0; i < mm; i++) {
		ma = max (dp[nn][i], ma);

	}
	cout << ma  << "\n";
}


#include <bits/stdc++.h>
#define MAX (ll)(5e5 + 7)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e17)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false);
#define LOG 20

using namespace std;
using ll = long long;
int dp[1 << 9], ch[1 << 9], l, pl[10];

int main () {
	int n, m, k;
	cin >> n >>  m >> k;
	set<int> se;
	vector<pair<int, int>> vp;
	for (int i = 1; i <= n; i++) {
		int l, r;
		cin >> l >> r;
		vp.push_back (make_pair (l, i));
		vp.push_back (make_pair (r + 1, -i));
	}
	for (int i = 0; i < k; i++) {
		se.insert (i);
	}
	for (int i = 1; i < (1 << k); i++) {
		dp[i] = -MOD, ch[i] = ch[i >> 1] ^ (i & 1);
	}
	sort (vp.begin (), vp.end ());
	for (int i = 0; i < vp.size (); i++) {
		int r = vp[i].first, x = vp[i].second;
		for (int i = 0; i < (1 << k); i++) {
			if (ch[i]) {
				dp[i] += r - l;
			}
		}
		l = r;
		if (x > 0) {
			pl[x] = *se.begin ();
			se.erase (se.begin ());
			for (int i = 0; i < (1 << k); i++) {
				if ((i >> pl[x]) & 1) {
					dp[i] = max (dp[i], dp[i ^ (1 << pl[x])]);
				}
			}
		}
		else {
			x *= -1;
			se.insert (pl[x]);
			for (int i = 0; i < (1 << k); i++) {
				if ((i >> pl[x]) & 1) {
					dp[i ^ (1 << pl[x])] = max (dp[i ^ (1 << pl[x])], dp[i]);
					dp[i] = -MOD;
				}
			}
		}
	}
	cout << dp[0] << "\n";
}


#include <bits/stdc++.h>
#define MAX (ll)(1e5 + 7)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e17)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false);
#define LOG 20

using namespace std;
using ll = long long;
vector<ll> vv[MAX];
ll dp[MAX][1 << 8];

int main () {
	ll n, m, k, cc = 0;
	cin >> n >> m >> k;
	vector<pair<ll, ll>> vp, el;
	set<ll> se;
	for (ll i = 0; i < n; i++) {
		ll l, r;
		cin >> l >> r;
		vp.push_back (make_pair (l, r));
		se.insert (l);
		se.insert (r);
	}
	sort (vp.begin (), vp.end ());
	for (auto it = se.begin (); ; ) {
		el.push_back (make_pair (*it, *it));
		if (*it != *se.rbegin ()) {
			ll x = *it, y = *(++it);
			if (x + 1 < y) {
				el.push_back (make_pair (x + 1, y - 1));
			}
		}
		else {
			break;
		}
	}
	ll st = 0;
	for (ll i = 0; i < n; i++) {
		while (st < el.size () && el[st].second < vp[i].first) {
			st++;
		}
		for (ll j = st; j < el.size () && el[j].first <= vp[i].second; j++) {
			vv[j].push_back (i);
		}
	}
	ll nn = el.size (), mm = (1 << k), mi = -1, ma = -1, len = 1;
	for (ll i = 0; i < nn; i++) {
		len = ma - mi + 1;
		ll d = vv[i].size () ? min (len, vv[i].front () - mi) : len;
		for (ll j = 0; j < mm; j++) {
			dp[0][j >> d] = max (dp[0][j >> d], dp[i][j]);
		}
		for (ll j = 0; j < mm; j++) {
			dp[i + 1][j] = dp[0][j];
			dp[0][j] = 0;
		}
		if (vv[i].size () == 0) {
			mi = ma;
			continue;
		}
		mi = vv[i].front ();
		d = vv[i].back () - ma;
		for (ll j = 0; j < (1 << d); j++) {
			bool fl =  __builtin_popcount (j) & 1;
			ll t = ma + 1 - vv[i].front ();
			assert (t >= 0);
			for (ll x = 0; x < (1 << t); x++) {
				ll ind = x | (j << t);
				ll co = (__builtin_popcount (ind) & 1) * (el[i].second - el[i].first + 1);
				dp[0][ind] = max (dp[i + 1][x] + co, dp[0][ind]);
			}
		}
		for (ll j = 0; j < mm; j++) {
			dp[i + 1][j] = dp[0][j];
			dp[0][j] = 0;
		}
		mi = vv[i].front (), ma = vv[i].back ();
	}
	ma = 0;
	for (ll i = 0; i < mm; i++) {
		ma = max (dp[nn][i], ma);

	}
	cout << ma  << "\n";
}


#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n,m,kk,num[N],ptr,dp[N][1 << 8];
struct Line {int l,r;} a[N];
vector<int> c[N];
int mp[10][10],mx[1 << 8];
int main ()
{
    ios::sync_with_stdio(false);
    cin >> n >> m >> kk;
    for (int i = 1;i <= n;i++)
        cin >> a[i].l >> a[i].r,num[++ptr] = --a[i].l,num[++ptr] = a[i].r;
    sort(num + 1,num + ptr + 1);ptr = unique(num + 1,num + ptr + 1) - num - 1;
    for (int i = 1;i <= n;i++)
    {
        a[i].l = lower_bound(num + 1,num + ptr + 1,a[i].l) - num;
        a[i].r = lower_bound(num + 1,num + ptr + 1,a[i].r) - num;
        for (int j = a[i].l + 1;j <= a[i].r;j++) c[j].push_back(i);
    }
    c[1].resize(kk);int lim = 1 << kk;
    // for (auto &i : c[1]) cout << i << ' ';
    // cout << endl;
    for (int i = 2;i <= ptr;i++)
    {
        auto tmp = c[i];c[i].clear();c[i].resize(kk);
        memset(mx,0,sizeof(mx));vector<int> nw;
        int mask = 0;
        for (auto &j : tmp)
        {
            bool ok = 0;
            for (int k = 0;k < kk && !ok;k++)
                if (j == c[i - 1][k]) c[i][k] = j,ok = 1,mask |= (1 << k);
            if (!ok) nw.push_back(j);
        }
        for (auto &j : c[i]) if (!j && !nw.empty()) j = nw.back(),nw.pop_back();
        // for (auto &j : c[i]) cout << j << ' ';
        // cout << endl;
        int used = 0;
        for (int j = 0;j < kk;j++) if (c[i][j]) used |= (1 << j);
        for (int j = 0;j < lim;j++) mx[j & mask] = max(mx[j & mask],dp[i - 1][j]);
        for (int j = 0;j < lim;j++)
        {
            dp[i][j] = mx[j & mask];
            if (__builtin_popcount(used & j) & 1) dp[i][j] += num[i] - num[i - 1];
            // cout << i << ' ' << j << ' ' << dp[i][j] << endl;
        }
    }
    cout << *max_element(dp[ptr],dp[ptr] + lim) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n,m,kk,num[N],ptr,dp[N][1 << 8];
struct Line {int l,r;} a[N];
vector<int> c[N];
int mp[10][10],mx[1 << 8];
int main ()
{
    ios::sync_with_stdio(false);
    cin >> n >> m >> kk;
    for (int i = 1;i <= n;i++)
        cin >> a[i].l >> a[i].r,num[++ptr] = --a[i].l,num[++ptr] = a[i].r;
    sort(num + 1,num + ptr + 1);ptr = unique(num + 1,num + ptr + 1) - num - 1;
    for (int i = 1;i <= n;i++)
    {
        a[i].l = lower_bound(num + 1,num + ptr + 1,a[i].l) - num;
        a[i].r = lower_bound(num + 1,num + ptr + 1,a[i].r) - num;
        for (int j = a[i].l + 1;j <= a[i].r;j++) c[j].push_back(i);
    }
    c[1].resize(kk);int lim = 1 << kk;
    for (int i = 2;i <= ptr;i++)
    {
        auto tmp = c[i];c[i].clear();c[i].resize(kk);
        memset(mx,0,sizeof(mx));vector<int> nw;
        int mask = 0;
        for (auto &j : tmp)
        {
            bool ok = 0;
            for (int k = 0;k < kk && !ok;k++)
                if (j == c[i - 1][k]) c[i][k] = j,ok = 1,mask |= (1 << k);
            if (!ok) nw.push_back(j);
        }
        for (auto &j : c[i]) if (!j && !nw.empty()) j = nw.back(),nw.pop_back();
        int used = 0;
        for (int j = 0;j < kk;j++) if (c[i][j]) used |= (1 << j);
        for (int j = 0;j < lim;j++) mx[j & mask] = max(mx[j & mask],dp[i - 1][j]);
        for (int j = 0;j < lim;j++)
        {
            dp[i][j] = mx[j & mask];
            if (__builtin_popcount(used & j) & 1) dp[i][j] += num[i] - num[i - 1];
        }
    }
    cout << *max_element(dp[ptr],dp[ptr] + lim) << endl;
    return 0;
}


#include <iostream>
#include <algorithm>

#define parity __builtin_parity
#define lowbit(x) ((x) & -(x))
#define max_3(a, b, c) max(a, std::max(b, c))

const int N = 200000 + 7, S = 1 << 8 | 7;

int n, m, k;
struct str {
	int x, y;
} a[N];
int b[N];
int e[N], l[N], r[N], z[N];
int f[S], g[S];

int main() {
	scanf("%d%d%d", &n, &m, &k), ++m;
	for (int i = 1; i <= n; ++i)
		scanf("%d%d", &a[i].x, &a[i].y), e[i] = --a[i].x, e[i + n] = a[i].y;
	std::sort(e + 1, e + n * 2 + 1);
	m = std::unique(e + 1, e + n * 2 + 1) - e - 1;
	for (int i = 1; i <= n; ++i)
		a[i].x = std::lower_bound(e + 1, e + m + 1, a[i].x) - e,
		a[i].y = std::lower_bound(e + 1, e + m + 1, a[i].y) - e;

	std::sort(a + 1, a + n + 1, [](str a, str b) {
		return a.x != b.x ? a.x < b.x : a.y < b.y;
	});
	for (int j = 1; j <= k; ++j)
		for (int i = 1, l = 0; i <= n; ++i)
			if (!b[i] && l <= a[i].x) b[i] = j, l = a[i].y;

	const int A = (1 << k) - 1;
	for (int i = 1; i <= n; ++i)
		l[a[i].x] |= 1 << b[i] - 1, r[a[i].y] |= 1 << b[i] - 1;
	for (int i = 1; i <= m; ++i)
		z[i] = z[i - 1] ^ r[i] | l[i];
	for (int i = 1; i <= m; ++i) {
		std::fill(g, g + A + 1, 0);
		for (int j = A, l, u, v; ~j; --j)
			l = r[i] ^ (j & r[i]), u = lowbit(l), v = lowbit(l ^ u),
			g[j] = std::max_3(f[j], g[j ^ u], g[j ^ v]);
		std::fill(f, f + A + 1, 0);
		for (int j = 0; j <= A; ++j)
			if ((z[i] & j) == j)
				f[j] = g[j & ~l[i] & ~r[i]] + parity(j) * (e[i + 1] - e[i]);
	}
	printf("%d", f[0]);

	return 0;
}


#include<bits/stdc++.h>
#define mxn 1000010
#define db double
#define LL long long
#define ldb long double
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair<int,int>
#define mp make_pair
#define fr first
#define sc second
#define x1 faqx1
#define y1 faqy1
#define x2 faqx2
#define y2 faqy2
using namespace std;
const int mod=998244353;
template<typename T> void chkmin(T &x,T y) {if(y<x) x=y;}
template<typename T> void chkmax(T &x,T y) {if(y>x) x=y;}
template<typename T> void upd(T &x,T y) {if((x+=y)>=mod) x-=mod;}
int n,m,K,N,sl,fh,ans,a[mxn],s[mxn],l[mxn],r[mxn],num[mxn];
int p[256],f[256],g[256],trs[256];
set<int> ex;
vector<int> add[mxn],del[mxn],pos[mxn];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	n=rd();m=rd();K=rd();
	for(int i=1;i<=n;++i) s[++N]=l[i]=rd()-1,s[++N]=r[i]=rd();
	sort(s+1,s+N+1);N=unique(s+1,s+N+1)-s-1;
	for(int i=1;i<=n;++i)
	{
		l[i]=lower_bound(s+1,s+N+1,l[i])-s;
		r[i]=lower_bound(s+1,s+N+1,r[i])-s;
		add[l[i]].pb(i);
		del[r[i]].pb(i);
	}
	for(int i=1;i<=N;++i)
	{
		for(auto v:ex) pos[i].pb(v);
		for(auto v:add[i]) ex.insert(v);
		for(auto v:del[i]) ex.erase(v);
		pos[i].resize(K);
	}
	for(int i=1;i<1<<K;++i) num[i]=num[i^(i&-i)]+1;
	int T,S=0;pos[N+1].resize(K);
	for(int k=1;k<=N;++k)
	{
		T=0;for(int i=0;i<K;++i) if(pos[k][i]) T|=1<<i;
		for(int x=0;x<1<<K;++x) f[x]=(num[x&T]&1)*(s[k]-s[k-1])+g[x&S];
		memset(p,0,sizeof(p));
		for(int i=0;i<K;++i)
			if(pos[k][i])
				for(int j=0;j<K;++j)
					if(pos[k][i]==pos[k+1][j])
						{p[1<<i]=1<<j; break;}
		memset(g,0,sizeof(g));g[0]=f[0];S=0;
		for(int x=1;x<1<<K;++x)
		{
			trs[x]=trs[x^(x&-x)]|p[x&-x];
			chkmax(g[trs[x]],f[x]);
		}
		for(int i=0;i<K;++i) if(p[1<<i]) S|=p[1<<i];
	}
	for(int i=0;i<1<<K;++i) chkmax(ans,f[i]);
	printf("%d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<bitset>
#include<cassert>
#define next MabLcdG
#define R register
#define debug puts("wn")
#define chkmax(x, y) (x=max(x, y))
#define chkmin(x, y) (x=min(x, y))
#define pos(x, y) ((x-1)*9+y)
#define mod 10000000071
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef double dl;
template<typename T> void read(T &x);
template<typename T> void write(T x);
template<typename T> void writesp(T x);
template<typename T> void writeln(T x);

const ll N=2e5+5, M=1<<9;

ll n, m, k;

struct node{
	ll pos, id;
	inline bool operator <(const node &X)const{
		return pos<X.pos;
	}
}q[N<<1];
ll f[M], s;
ll cnt;
ll vis[N];

inline ll popcount(ll x){
	ll res=0;
	for (; x; x-=x&-x) res^=1;
	return res;
}

int main(){
	read(n); read(m); read(k); s=255;
	for (R ll i=1, x, y; i<=n; i++){
		read(x); read(y);
		q[++cnt]=(node){x, i};
		q[++cnt]=(node){y+1, -i};
	}
	for (R ll i=1; i<=s; i++) f[i]=-0x7fffffff;
	sort(q+1, q+cnt+1);
	for (R ll i=1, len, pos; i<=cnt; i++){
		len=(i==cnt)?0:q[i+1].pos-q[i].pos;
		if (q[i].id>0){
			for (R ll j=0; j<8; j++){
				if (!vis[j]){
					pos=j;
					vis[j]=q[i].id;
					break;
				}
			}
			for (R ll j=s; ~j; j--){
				if (j>>pos&1){
					f[j]=f[j^(1<<pos)]+len*popcount(j);
				}else f[j]+=len*popcount(j);
			}
		}else {
			for (R ll j=0; j<8; j++){
				if (vis[j]==-q[i].id){
					pos=j;
					vis[j]=0;
					break;
				}
			}
			for (R ll j=0; j<=s; j++){
				if (j>>pos&1) f[j]=-0x7fffffff;
				else chkmax(f[j], f[j^(1<<pos)])+=len*popcount(j);
			}

		}
	}
	writeln(f[0]);
}
template<typename T> void read(T &x){
	x=0; int t=1;
	char wn=getchar();
	while (wn<'0' || wn>'9'){
		if (wn=='-') t=-1;
		wn=getchar();
	}
	while (wn>='0' && wn<='9'){
		x=x*10+wn-'0'; wn=getchar();
	}
	x*=t;
}
template<typename T> void write(T x){
	if (x<0){putchar('-'); x=-x;}
	if (x<=9){putchar(x+'0'); return;}
	write(x/10); putchar(x%10+'0');
}
template<typename T> void writesp(T x){
	write(x); putchar(' ');
}

template<typename T> void writeln(T x){
	write(x); putchar('\n');
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<bitset>
#include<cassert>
#define next MabLcdG
#define R register
#define debug puts("wn")
#define chkmax(x, y) (x=max(x, y))
#define chkmin(x, y) (x=min(x, y))
#define pos(x, y) ((x-1)*9+y)
#define mod 10000000071
using namespace std;
typedef int ll;
typedef long double ld;
typedef unsigned long long ull;
typedef double dl;
template<typename T> void read(T &x);
template<typename T> void write(T x);
template<typename T> void writesp(T x);
template<typename T> void writeln(T x);

const ll N=2e5+5, M=1<<9;

ll n, m, k;

struct node{
	ll pos, id;
	inline bool operator <(const node &X)const{
		return pos<X.pos;
	}
}q[N<<1];
ll f[M], s;
ll cnt;
ll vis[N];

inline ll popcount(ll x){
	ll res=0;
	for (; x; x-=x&-x) res^=1;
	return res;
}

int main(){
	read(n); read(m); read(k); s=255;
	for (R ll i=1, x, y; i<=n; i++){
		read(x); read(y);
		q[++cnt]=(node){x, i};
		q[++cnt]=(node){y+1, -i};
	}
	for (R ll i=1; i<=s; i++) f[i]=-0x7fffffff;
	sort(q+1, q+cnt+1);
	for (R ll i=1, len, pos; i<=cnt; i++){
		len=(i==cnt)?0:q[i+1].pos-q[i].pos;
		if (q[i].id>0){
			for (R ll j=0; j<8; j++){
				if (!vis[j]){
					pos=j;
					vis[j]=q[i].id;
					break;
				}
			}
			for (R ll j=s; ~j; j--){
				if (j>>pos&1){
					f[j]=f[j^(1<<pos)]+len*popcount(j);
				}else f[j]+=len*popcount(j);
			}
		}else {
			for (R ll j=0; j<8; j++){
				if (vis[j]==-q[i].id){
					pos=j;
					vis[j]=0;
					break;
				}
			}
			for (R ll j=0; j<=s; j++){
				if (j>>pos&1) f[j]=-0x7fffffff;
				else chkmax(f[j], f[j^(1<<pos)])+=len*popcount(j);
			}

		}
	}
	writeln(f[0]);
}
template<typename T> void read(T &x){
	x=0; int t=1;
	char wn=getchar();
	while (wn<'0' || wn>'9'){
		if (wn=='-') t=-1;
		wn=getchar();
	}
	while (wn>='0' && wn<='9'){
		x=x*10+wn-'0'; wn=getchar();
	}
	x*=t;
}
template<typename T> void write(T x){
	if (x<0){putchar('-'); x=-x;}
	if (x<=9){putchar(x+'0'); return;}
	write(x/10); putchar(x%10+'0');
}
template<typename T> void writesp(T x){
	write(x); putchar(' ');
}

template<typename T> void writeln(T x){
	write(x); putchar('\n');
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 100005;

vector< pair<int, int> > a;
int f[1 << 8], vis[8];
int main() {
    int n;
    scanf("%d%*d%*d", &n);
    for (int i = 1; i <= n; i++) {
        int l, r;
        scanf("%d%d", &l, &r);
        a.push_back({l, i});
        a.push_back({r + 1, -i});
    }
    sort(a.begin(), a.end());
    for (int i = 1; i < 256; i++) f[i] = -INF;
    for (int u = 0; u < a.size(); u++) {
        int id = a[u].second, k;
        int len = u == a.size() - 1 ? 0 : a[u + 1].first - a[u].first;
        if (id > 0) {
            for (int i = 0; i < 8; i++) {
                if (vis[i] == 0) {
                    vis[k = i] = id;
                    break;
                }
            }
            for (int i = 255; i >= 0; i--) {
                if (i >> k & 1) {
                    f[i] = f[i ^ 1 << k] + len * __builtin_parity(i);
                } else {
                    f[i] = f[i] + len * __builtin_parity(i);
                }
            }
        } else {
            for (int i = 0; i < 8; i++) {
                if (vis[i] == -id) {
                    vis[k = i] = 0;
                    break;
                }
            }
            for (int i = 255; i >= 0; i--) {
                if (i >> k & 1) {
                    f[i] = -INF;
                } else {
                    f[i] = max(f[i], f[i ^ 1 << k]) + len * __builtin_parity(i);
                }
            }
        }
    }
    printf("%d\n", f[0]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> bool mmax(T &m, const T q) { if (m < q) { m = q; return true; } else return false; }
template<typename T> bool mmin(T &m, const T q) { if (q < m) { m = q; return true; } else return false; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

constexpr int INF = 1.1e9;
int main()
{
	int N, M, K;
	cin >> N >> M >> K;
	vector<pint> lr(N);
	for (auto &p : lr) cin >> p.first >> p.second;
	sort(lr.begin(), lr.end());

	set<int> z;
	for (auto p : lr) z.insert(p.first), z.insert(p.second + 1);

	map<int, vector<int>> l2r;
	for (auto p : lr) l2r[p.first].push_back(p.second + 1);

	vector<int> dp(1 << K, -INF);
	dp[0] = 0;
	vector<int> R(K, 0);
	int exist = 0;
	int xp = 0;
	for (auto x : z)
	{
		for (int S = 0; S < (1 << K); ++S)
			if (!((~exist) & S) and(__builtin_popcount(S) & 1))
				dp[S] += x - xp;
		for (int d = 0; d < K; ++d)
			if (R[d] == x)
			{
				R[d] = 0;
				exist -= 1 << d;
				for (int S = 0; S < (1 << K); ++S)
					if ((S >> d) & 1)
					{
						mmax(dp[S - (1 << d)], dp[S]);
						dp[S] = -INF;
					}
			}
		for (auto nxtr : l2r[x])
		{
			int d = 0;
			while (R[d]) d++;
			R[d] = nxtr;
			exist += 1 << d;
			for (int S = 0; S < (1 << K); ++S)
				if ((S >> d) & 1)
					mmax(dp[S], dp[S - (1 << d)]);
		}
		xp = x;
	}
	cout << *max_element(dp.begin(), dp.end()) << endl;
}


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

template<typename T> bool mmax(T &m, const T q) { if (m < q) { m = q; return true; } else return false; }
template<typename T> bool mmin(T &m, const T q) { if (q < m) { m = q; return true; } else return false; }

constexpr int INF = 1.1e9;

int main()
{
	int N, M, K;
	cin >> N >> M >> K;
	vector<pair<int, int>> lr(N);
	for (auto &p : lr) cin >> p.first >> p.second;
	//sort(lr.begin(), lr.end());

	set<int> z;
	for (auto p : lr) z.insert(p.first), z.insert(p.second + 1);

	map<int, vector<int>> l2r;
	for (auto p : lr) l2r[p.first].push_back(p.second + 1);

	vector<int> dp(1 << K, -1.1e9);
	dp[0] = 0;
	vector<int> R(K, 0);
	int exist = 0;
	int xp = 0;
	for (auto x : z)
	{
		for (int S = 0; S < (1 << K); ++S)
			if (!((~exist) & S) and(__builtin_popcount(S) & 1))
				dp[S] += x - xp;
		for (int d = 0; d < K; ++d)
			if (R[d] == x)
			{
				R[d] = 0;
				exist -= 1 << d;
				for (int S = 0; S < (1 << K); ++S)
					if ((S >> d) & 1)
					{
						mmax(dp[S - (1 << d)], dp[S]);
						dp[S] = -INF;
					}
			}
		for (auto nxtr : l2r[x])
		{
			int d = 0;
			while (R[d]) d++;
			R[d] = nxtr;
			exist += 1 << d;
			for (int S = 0; S < (1 << K); ++S)
				if ((S >> d) & 1)
					mmax(dp[S], dp[S - (1 << d)]);
		}
		xp = x;
	}
	cout << *max_element(dp.begin(), dp.end()) << endl;
}


#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1 << 9, M = 110000, inf = 1e9;

int n, m, k, f[N], pc[N], ind[M];
map<int, vector<pii> > app;
set<int> unu;

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	int x, y;
	read(n), read(m), read(k);
	for (R int i = 1; i <= n; ++i) {
		read(x), read(y);
		app[x].push_back(mp(0, i));
		app[y + 1].push_back(mp(1, i));
	}
	int lst = 0;
	for (R int i = 0; i < k; ++i) unu.insert(i);
	for (R int i = 1; i < 1 << k; ++i)
		f[i] = -inf, pc[i] = pc[i >> 1] ^ (i & 1);
	for (auto &v : app) {
		for (R int i = 0; i < 1 << k; ++i)
			if (pc[i]) f[i] += v.first - lst;
		lst = v.first;
		sort(v.second.begin(), v.second.end());
		for (auto &u : v.second) {
			if (u.first == 1) {
				unu.insert(ind[u.second]);
				for (R int i = 0; i < 1 << k; ++i)
					if (i & (1 << ind[u.second])) {
						f[i ^ (1 << ind[u.second])] = max(f[i ^ (1 << ind[u.second])], f[i]);
						f[i] = -inf;
					}
			}
			else {
			    assert(!unu.empty());
				ind[u.second] = *unu.begin();
				unu.erase(unu.begin());
				for (R int i = 0; i < 1 << k; ++i)
					if (i & (1 << ind[u.second]))
						f[i] = max(f[i ^ (1 << ind[u.second])], f[i]);
			}
		}
	}
	cout << f[0] << endl;
	return 0;
}


#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1 << 9, M = 110000, inf = 1e9;

int n, m, k, f[N], pc[N], ind[M];
map<int, vector<pii> > app;
set<int> unu;

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	int x, y;
	read(n), read(m), read(k);
	for (R int i = 1; i <= n; ++i) {
		read(x), read(y);
		app[x].push_back(mp(0, i));
		app[y + 1].push_back(mp(1, i));
	}
	int lst = 0;
	for (R int i = 0; i < k; ++i) unu.insert(i);
	for (R int i = 1; i < 1 << k; ++i)
		f[i] = -inf, pc[i] = pc[i >> 1] ^ (i & 1);
	for (auto v : app) {
		for (R int i = 0; i < 1 << k; ++i)
			if (pc[i]) f[i] += v.first - lst;
		lst = v.first;
		sort(v.second.begin(), v.second.end());
		for (auto u : v.second) {
			if (u.first == 1) {
				unu.insert(ind[u.second]);
				for (R int i = 0; i < 1 << k; ++i)
					if (i & (1 << ind[u.second])) {
						f[i ^ (1 << ind[u.second])] = max(f[i ^ (1 << ind[u.second])], f[i]);
						f[i] = -inf;
					}
			}
			else {
				ind[u.second] = *unu.begin();
				unu.erase(unu.begin());
				for (R int i = 0; i < 1 << k; ++i)
					if (i & (1 << ind[u.second]))
						f[i] = max(f[i ^ (1 << ind[u.second])], f[i]);
			}
		}
	}
	cout << f[0] << endl;
	return 0;
}


#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1 << 9, M = 110000, inf = 1e9;

int n, m, k, f[N], pc[N], ind[M];
map<int, vector<pii> > app;
set<int> unu;

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	int x, y;
	read(n), read(m), read(k);
	for (R int i = 1; i <= n; ++i) {
		read(x), read(y);
		app[x].push_back(mp(0, i));
		app[y + 1].push_back(mp(1, i));
	}
	int lst = 0;
	for (R int i = 0; i < k; ++i) unu.insert(i);
	for (R int i = 1; i < 1 << k; ++i)
		f[i] = -inf, pc[i] = pc[i >> 1] ^ (i & 1);
	for (auto &v : app) {
		for (R int i = 0; i < 1 << k; ++i)
			if (pc[i]) f[i] += v.first - lst;
		lst = v.first;
		if (n < 100) sort(v.second.begin(), v.second.end());
		for (auto &u : v.second) {
			if (u.first == 1) {
				unu.insert(ind[u.second]);
				for (R int i = 0; i < 1 << k; ++i)
					if (i & (1 << ind[u.second])) {
						f[i ^ (1 << ind[u.second])] = max(f[i ^ (1 << ind[u.second])], f[i]);
						f[i] = -inf;
					}
			}
			else {
				ind[u.second] = *unu.begin();
				unu.erase(unu.begin());
				for (R int i = 0; i < 1 << k; ++i)
					if (i & (1 << ind[u.second]))
						f[i] = max(f[i ^ (1 << ind[u.second])], f[i]);
			}
		}
	}
	cout << f[0] << endl;
	return 0;
}


#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1 << 9, M = 110000, inf = 1e9;

int n, m, k, f[N], pc[N], ind[M];
map<int, vector<pii> > app;
set<int> unu;

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	int x, y;
	read(n), read(m), read(k);
	for (R int i = 1; i <= n; ++i) {
		read(x), read(y);
		app[x].push_back(mp(0, i));
		app[y + 1].push_back(mp(1, i));
	}
	int lst = 0;
	for (R int i = 0; i < k; ++i) unu.insert(i);
	for (R int i = 1; i < 1 << k; ++i)
		f[i] = -inf, pc[i] = pc[i >> 1] ^ (i & 1);
	for (auto &v : app) {
		for (R int i = 0; i < 1 << k; ++i)
			if (pc[i]) f[i] += v.first - lst;
		lst = v.first;
		sort(v.second.begin(), v.second.end());
		for (auto &u : v.second) {
			if (u.first == 1) {
				unu.insert(ind[u.second]);
				for (R int i = 0; i < 1 << k && n < 100; ++i)
					if (i & (1 << ind[u.second])) {
						f[i ^ (1 << ind[u.second])] = max(f[i ^ (1 << ind[u.second])], f[i]);
						f[i] = -inf;
					}
			}
			else {
				ind[u.second] = *unu.begin();
				unu.erase(unu.begin());
				for (R int i = 0; i < 1 << k && n < 100; ++i)
					if (i & (1 << ind[u.second]))
						f[i] = max(f[i ^ (1 << ind[u.second])], f[i]);
			}
		}
	}
	cout << f[0] << endl;
	return 0;
}


#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1 << 9, M = 110000, inf = 1e9;

int n, m, k, f[N], pc[N], ind[M];
map<int, vector<pii> > app;
set<int> unu;

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	int x, y;
	read(n), read(m), read(k);
	for (R int i = 1; i <= n; ++i) {
		read(x), read(y);
		app[x].push_back(mp(0, i));
		app[y + 1].push_back(mp(1, i));
	}
	int lst = 0;
	for (R int i = 0; i < k; ++i) unu.insert(i);
	for (R int i = 1; i < 1 << k; ++i)
		f[i] = -inf, pc[i] = pc[i >> 1] ^ (i & 1);
	for (auto &v : app) {
		for (R int i = 0; i < 1 << k; ++i)
			if (pc[i]) f[i] += v.first - lst;
		lst = v.first;
		sort(v.second.begin(), v.second.end());
		for (auto &u : v.second) {
		    if (n > 100)
		    {
		        assert(u.second <= n);
		        continue;
		    }
			if (u.first == 1) {
				unu.insert(ind[u.second]);
				for (R int i = 0; i < 1 << k; ++i)
					if (i & (1 << ind[u.second])) {
						f[i ^ (1 << ind[u.second])] = max(f[i ^ (1 << ind[u.second])], f[i]);
						f[i] = -inf;
					}
			}
			else {
				ind[u.second] = *unu.begin();
				unu.erase(unu.begin());
				for (R int i = 0; i < 1 << k; ++i)
					if (i & (1 << ind[u.second]))
						f[i] = max(f[i ^ (1 << ind[u.second])], f[i]);
			}
		}
	}
	cout << f[0] << endl;
	return 0;
}


#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1 << 9, M = 110000, inf = 1e9;

int n, m, k, f[N], pc[N], ind[M];
set<int> unu;
vector<pii> app;

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	int x, y;
	read(n), read(m), read(k);
	for (R int i = 1; i <= n; ++i) {
		read(x), read(y);
		app.push_back(mp(x, i));
		app.push_back(mp(y + 1, -i));
	}
	sort(app.begin(), app.end());
	int lst = 0;
	for (R int i = 0; i < k; ++i) unu.insert(i);
	for (R int i = 1; i < 1 << k; ++i)
		f[i] = -inf, pc[i] = pc[i >> 1] ^ (i & 1);
	for (auto &v : app) {
		for (R int i = 0; i < 1 << k; ++i)
			if (pc[i]) f[i] += v.first - lst;
		lst = v.first;
		if (v.second > 0) {
		    assert(!unu.empty());
			ind[v.second] = *unu.begin();
			unu.erase(unu.begin());
			for (R int i = 0; i < 1 << k; ++i)
				if (i & (1 << ind[v.second]))
					f[i] = max(f[i ^ (1 << ind[v.second])], f[i]);
		}
		else {
			v.second *= -1;
			unu.insert(ind[v.second]);
			for (R int i = 0; i < 1 << k; ++i)
				if (i & (1 << ind[v.second])) {
					f[i ^ (1 << ind[v.second])] = max(f[i ^ (1 << ind[v.second])], f[i]);
					f[i] = -inf;
				}
		}
	}
	cout << f[0] << endl;
	return 0;
}


#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1 << 9, M = 110000, inf = 1e9;

int n, m, k, f[N], pc[N], ind[M];
map<int, vector<pii> > app;
set<int> unu;

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	int x, y;
	read(n), read(m), read(k);
	for (R int i = 1; i <= n; ++i) {
		read(x), read(y);
		app[x].push_back(mp(0, i));
		app[y + 1].push_back(mp(1, i));
	}
	int lst = 0;
	for (R int i = 0; i < k; ++i) unu.insert(i);
	for (R int i = 1; i < 1 << k; ++i)
		f[i] = -inf, pc[i] = pc[i >> 1] ^ (i & 1);
	for (auto &v : app) {
		for (R int i = 0; i < 1 << k; ++i)
			if (pc[i]) f[i] += v.first - lst;
		lst = v.first;
		sort(v.second.begin(), v.second.end());
		for (auto &u : v.second) {
		    assert(u.second <= n);
		}
	}
	cout << f[0] << endl;
	return 0;
}


#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1 << 9, M = 110000, inf = 1e9;

int n, m, k, f[N], pc[N], ind[M];
map<int, vector<pii> > app;
set<int> unu;

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	int x, y;
	read(n), read(m), read(k);
	for (R int i = 1; i <= n; ++i) {
		read(x), read(y);
		app[x].push_back(mp(0, i));
		app[y + 1].push_back(mp(1, i));
	}
	int lst = 0;
	for (R int i = 0; i < k; ++i) unu.insert(i);
	for (R int i = 1; i < 1 << k; ++i)
		f[i] = -inf, pc[i] = pc[i >> 1] ^ (i & 1);
	if (n > 100) return 0;
	for (auto &v : app) {
		for (R int i = 0; i < 1 << k; ++i)
			if (pc[i]) f[i] += v.first - lst;
		lst = v.first;
		sort(v.second.begin(), v.second.end());
		for (auto &u : v.second) {
			if (u.first == 1) {
				unu.insert(ind[u.second]);
				for (R int i = 0; i < 1 << k; ++i)
					if (i & (1 << ind[u.second])) {
						f[i ^ (1 << ind[u.second])] = max(f[i ^ (1 << ind[u.second])], f[i]);
						f[i] = -inf;
					}
			}
			else {
				ind[u.second] = *unu.begin();
				unu.erase(unu.begin());
				for (R int i = 0; i < 1 << k; ++i)
					if (i & (1 << ind[u.second]))
						f[i] = max(f[i ^ (1 << ind[u.second])], f[i]);
			}
		}
	}
	cout << f[0] << endl;
	return 0;
}


#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1 << 9, M = 110000, inf = 1e9;

int n, m, k, f[N], pc[N], ind[M];
map<int, vector<pii> > app;
set<int> unu;

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	int x, y;
	read(n), read(m), read(k);
	for (R int i = 1; i <= n; ++i) {
		read(x), read(y);
		app[x].push_back(mp(0, i));
		app[y + 1].push_back(mp(1, i));
	}
	int lst = 0;
	for (R int i = 0; i < k; ++i) unu.insert(i);
	for (R int i = 1; i < 1 << k; ++i)
		f[i] = -inf, pc[i] = pc[i >> 1] ^ (i & 1);
	for (auto &v : app) {
		for (R int i = 0; i < 1 << k; ++i)
			if (pc[i]) f[i] += v.first - lst;
		lst = v.first;
		sort(v.second.begin(), v.second.end());
		for (auto &u : v.second) {
			if (u > n) return 1;
		}
	}
	cout << f[0] << endl;
	return 0;
}


#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1 << 9, M = 110000, inf = 1e9;

int n, m, k, f[N], pc[N], ind[M];
map<int, vector<pii> > app;
set<int> unu;

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	int x, y;
	read(n), read(m), read(k);
	for (R int i = 1; i <= n; ++i) {
		read(x), read(y);
		app[x].push_back(mp(0, i));
		app[y + 1].push_back(mp(1, i));
	}
	int lst = 0;
	for (R int i = 0; i < k; ++i) unu.insert(i);
	for (R int i = 1; i < 1 << k; ++i)
		f[i] = -inf, pc[i] = pc[i >> 1] ^ (i & 1);
	for (auto qwq : app) {
	    auto v = qwq;
		for (R int i = 0; i < 1 << k; ++i)
			if (pc[i]) f[i] += v.first - lst;
		lst = v.first;
		sort(v.second.begin(), v.second.end());
		for (auto &u : v.second) {
			if (u.first == 1) {
				unu.insert(ind[u.second]);
				for (R int i = 0; i < 1 << k; ++i)
					if (i & (1 << ind[u.second])) {
						f[i ^ (1 << ind[u.second])] = max(f[i ^ (1 << ind[u.second])], f[i]);
						f[i] = -inf;
					}
			}
			else {
				ind[u.second] = *unu.begin();
				unu.erase(unu.begin());
				for (R int i = 0; i < 1 << k; ++i)
					if (i & (1 << ind[u.second]))
						f[i] = max(f[i ^ (1 << ind[u.second])], f[i]);
			}
		}
	}
	cout << f[0] << endl;
	return 0;
}


#pragma GCC optimize(3)
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define reaD() read()
#define pb push_back
#define mkp make_pair
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i, k, j) for(register int i = (k); i >= (j); i--)
#define For(i, k, j) for(register int i = (k); i <= (j); i++)
#define DEBUG fprintf(stderr, "***IAKIOI***\n")
#define CDEBUG cerr << "***IAKIOI***" << endl;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const int P = 998244353; //
using namespace std;
inline void ckmax(int &a, int b) {a = max(a, b);}
inline void ckmin(int &a, int b) {a = min(a, b);}
inline void addmod(int &a, int b) {int t = a + b; a = (t >= P ? t - P : t); }
inline int ksm(int a, int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline int inv(int a) {return ksm(a, P-2);}
inline int read() {
    int num=0,flag=1;char c=' ';
    for(;!isdigit(c);c=getchar()) if(c=='-') flag=-1;
    for(;isdigit(c);num=num*10+c-48,c=getchar());
    return num*flag;
}
const int MAXN = 400005;
struct Line {
	int l, r;
	bool operator < (const Line b) const {return l != b.l ? l < b.l : r < b.r;}
}p[MAXN];
int disc[MAXN], dcnt = 0, n, m, K, t, used[MAXN], id[9][MAXN], ed[9][MAXN], mst[MAXN], mask[MAXN], f[2][1 << 9];
int siz[MAXN], adt[1 << 9];
void init() {
	sort(disc + 1, disc + 1 + dcnt);
	t = unique(disc + 1, disc + 1 + dcnt) - disc - 1;
	For(i, 1, n) {
		p[i].l = lower_bound(disc + 1, disc + 1 + t, p[i].l) - disc;
		siz[p[i].l] = disc[p[i].l] - disc[p[i].l-1];
		p[i].r = lower_bound(disc + 1, disc + 1 + t, p[i].r) - disc;
		siz[p[i].r] = disc[p[i].r] - disc[p[i].r-1];
	}
	For(i, 1, t) siz[i] = disc[i] - disc[i-1];
}
signed main()
{
	cin >> n >> m >> K;
	For(i, 1, n)
		p[i].l = read(), p[i].r = read(), disc[++dcnt] = p[i].l, disc[++dcnt] = p[i].r, disc[++dcnt] = max(p[i].l - 1, 1);
	init();
	sort(p + 1, p + 1 + n);
//	For(i, 1, n)
//		printf("%d %d\n", p[i].l, p[i].r);
//	For(i, 1, t)
//		printf("%d\n", siz[i]);
//	printf("\n");
	For(i, 0, K-1) {
		int lst = 0, cnt = 0;
		For(j, 1, n) {
			if(!used[j] && p[j].l > lst) {
				lst = p[j].r; used[j] = 1; cnt++;
//				cout << j << ' ';
				For(k, p[j].l, p[j].r)
					id[i][k] = cnt;
				ed[i][p[j].r] = 1;
			}
		}
//		cout << endl;
	}

	For(j, 1, t)
		For(i, 0, K-1)
			mst[j] |= (1 << i) * (id[i][j] != 0), mask[j] |= (1 << i) * (ed[i][j] == 1);
//	For(i, 1, t) {
//		printf("%d\n", mst[i]);
//	}
//	puts("");
	For(i, 0, (1 << K) - 1) adt[i] = (__builtin_popcount(i) & 1);
	For(i, 1, t) {
		memset(f[i&1], 0, sizeof(f[i&1]));
		For(j, 0, (1 << K) - 1) {
			if((j | mst[i]) != mst[i]) continue;
			int lst = (j & mst[i-1]) & (mask[i-1] ^ mst[i-1]);
			for(int k = mask[i-1]; k; k = (k - 1) & mask[i-1])
				ckmax(f[i&1][j], f[(i&1)^1][lst | k] + adt[j] * siz[i]);
			ckmax(f[i&1][j], f[(i&1)^1][lst] + adt[j] * siz[i]) ;
		}
//		For(j, 0, (1 << K) - 1) {
//			printf("%d ", f[i&1][j]);
//		}
//		printf("\n");
	}
	int res = 0;
	For(j, 0, (1 << K) - 1) ckmax(res, f[t&1][j]);
	cout << res << endl;
    return 0;
}


#pragma GCC optimize(3)
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define reaD() read()
#define pb push_back
#define mkp make_pair
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i, k, j) for(register int i = (k); i >= (j); i--)
#define For(i, k, j) for(register int i = (k); i <= (j); i++)
#define DEBUG fprintf(stderr, "***IAKIOI***\n")
#define CDEBUG cerr << "***IAKIOI***" << endl;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const int P = 998244353; //
using namespace std;
inline void ckmax(int &a, int b) {a = max(a, b);}
inline void ckmin(int &a, int b) {a = min(a, b);}
inline void addmod(int &a, int b) {int t = a + b; a = (t >= P ? t - P : t); }
inline int ksm(int a, int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline int inv(int a) {return ksm(a, P-2);}
inline int read() {
    int num=0,flag=1;char c=' ';
    for(;!isdigit(c);c=getchar()) if(c=='-') flag=-1;
    for(;isdigit(c);num=num*10+c-48,c=getchar());
    return num*flag;
}
const int MAXN = 400005;
struct Line {
	int l, r;
	bool operator < (const Line b) const {return l < b.l;}
}p[MAXN];
int a[9][MAXN], disc[MAXN], dcnt = 0, n, m, K, t, used[MAXN], id[9][MAXN], mst[MAXN], f[2][1 << 9];
void init() {
	sort(disc + 1, disc + 1 + dcnt);
	t = unique(disc + 1, disc + 1 + dcnt) - disc - 1;
	For(i, 1, n) {
		p[i].l = lower_bound(disc + 1, disc + 1 + t, p[i].l) - disc;
		p[i].r = lower_bound(disc + 1, disc + 1 + t, p[i].r) - disc;
	}

}
signed main()
{
	cin >> n >> m >> K;
	For(i, 1, n)
		p[i].l = read(), p[i].r = read(), disc[++dcnt] = p[i].l, disc[++dcnt] = p[i].r;
	init();
	sort(p + 1, p + 1 + n);
	For(i, 0, K-1) {
		int lst = 0, cnt = 0;
		For(j, 1, n) {
			if(!used[j] && p[j].l > lst) {
				lst = p[j].r; used[j] = 1;
				a[i][++cnt] = j;
				For(k, p[j].l, p[j].r)
					id[i][k] = cnt;
			}
		}
	}
	For(i, 1, n) assert(used[i] == 1);
	For(j, 1, t)
		For(i, 0, K-1)
			mst[j] |= (1 << i) * (id[i][j] != 0);
	For(i, 1, t) {
		memset(f[i&1], 0, sizeof(f[i&1]));
		For(st, 0, (1 << K) - 1) {
			if(st & mst[i] != mst[i]) continue;
			int adt = (__builtin_popcount(st) & 1);
			f[i&1][st] = f[(i&1)^1][st & mst[i-1]] + adt;
		}
	}
	int res = 0;
	For(st, 0, (1 << K) - 1) ckmax(res, f[t&1][st]);
	cout << res << endl;
    return 0;
}


#pragma GCC optimize(3)
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define reaD() read()
#define pb push_back
#define mkp make_pair
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i, k, j) for(register int i = (k); i >= (j); i--)
#define For(i, k, j) for(register int i = (k); i <= (j); i++)
#define DEBUG fprintf(stderr, "***IAKIOI***\n")
#define CDEBUG cerr << "***IAKIOI***" << endl;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const int P = 998244353; //
using namespace std;
inline void ckmax(int &a, int b) {a = max(a, b);}
inline void ckmin(int &a, int b) {a = min(a, b);}
inline void addmod(int &a, int b) {int t = a + b; a = (t >= P ? t - P : t); }
inline int ksm(int a, int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline int inv(int a) {return ksm(a, P-2);}
inline int read() {
    int num=0,flag=1;char c=' ';
    for(;!isdigit(c);c=getchar()) if(c=='-') flag=-1;
    for(;isdigit(c);num=num*10+c-48,c=getchar());
    return num*flag;
}
const int MAXN = 400005;
struct Line {
	int l, r;
	bool operator < (const Line b) const {return l != b.l ? l < b.l : r < b.r;}
}p[MAXN];
int disc[MAXN], dcnt = 0, n, m, K, t, used[MAXN], id[9][MAXN], ed[9][MAXN], mst[MAXN], mask[MAXN], f[2][1 << 9];
int siz[MAXN], adt[1 << 9];
void init() {
	sort(disc + 1, disc + 1 + dcnt);
	t = unique(disc + 1, disc + 1 + dcnt) - disc - 1;
	For(i, 1, n) {
		p[i].l = lower_bound(disc + 1, disc + 1 + t, p[i].l) - disc;
		siz[p[i].l] = disc[p[i].l] - disc[p[i].l-1];
		p[i].r = lower_bound(disc + 1, disc + 1 + t, p[i].r) - disc;
		siz[p[i].r] = disc[p[i].r] - disc[p[i].r-1];
	}
	For(i, 1, t) siz[i] = disc[i] - disc[i-1];
}
signed main()
{
	cin >> n >> m >> K;
	For(i, 1, n)
		p[i].l = read(), p[i].r = read(), disc[++dcnt] = p[i].l, disc[++dcnt] = p[i].r, disc[++dcnt] = max(p[i].l - 1, 1);
	init();
	sort(p + 1, p + 1 + n);
	For(i, 0, K-1) {
		int lst = 0, cnt = 0;
		For(j, 1, n) {
			if(!used[j] && p[j].l > lst) {
				lst = p[j].r; used[j] = 1; cnt++;
				For(k, p[j].l, p[j].r)
					id[i][k] = cnt;
				ed[i][p[j].r] = 1;
			}
		}
	}
	For(j, 1, t)
		For(i, 0, K-1)
			mst[j] |= (1 << i) * (id[i][j] != 0), mask[j] |= (1 << i) * (ed[i][j] != 0);
	For(i, 0, (1 << K) - 1) adt[i] = __builtin_popcount(i) & 1;
	For(i, 1, t) {
		memset(f[i&1], 0, sizeof(f[i&1]));
		For(j, 0, (1 << K) - 1) {
			if((j | mst[i]) != mst[i]) continue;
			int lst = (j & mst[i-1]);
			for(int k = mask[i-1]; k; k = (k - 1) & mask[i-1])
				ckmax(f[i&1][j], f[(i&1)^1][lst | k] + adt[j] * siz[i]);
			ckmax(f[i&1][j], f[(i&1)^1][lst] + adt[j] * siz[i]) ;
		}
//		For(j, 0, (1 << K) - 1) {
//			printf("%d ", f[i&1][j]);
//		}
//		printf("\n");
	}
	int res = 0;
	For(j, 0, (1 << K) - 1) ckmax(res, f[t&1][j]);
	cout << res << endl;
    return 0;
}

 /*
3 6 3
1 1
2 5
5 6

1 5 1
3 5
 */


#pragma GCC optimize(3)
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define reaD() read()
#define pb push_back
#define mkp make_pair
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i, k, j) for(register int i = (k); i >= (j); i--)
#define For(i, k, j) for(register int i = (k); i <= (j); i++)
#define DEBUG fprintf(stderr, "***IAKIOI***\n")
#define CDEBUG cerr << "***IAKIOI***" << endl;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const int P = 998244353; //
using namespace std;
inline void ckmax(int &a, int b) {a = max(a, b);}
inline void ckmin(int &a, int b) {a = min(a, b);}
inline void addmod(int &a, int b) {int t = a + b; a = (t >= P ? t - P : t); }
inline int ksm(int a, int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline int inv(int a) {return ksm(a, P-2);}
inline int read() {
    int num=0,flag=1;char c=' ';
    for(;!isdigit(c);c=getchar()) if(c=='-') flag=-1;
    for(;isdigit(c);num=num*10+c-48,c=getchar());
    return num*flag;
}
const int MAXN = 400005;
struct Line {
	int l, r;
	bool operator < (const Line b) const {return l != b.l ? l < b.l : r < b.r;}
}p[MAXN];
int a[9][MAXN], disc[MAXN], dcnt = 0, n, m, K, t, used[MAXN], id[9][MAXN], ed[9][MAXN], mst[MAXN], mask[MAXN], f[2][1 << 9];
int siz[MAXN], adt[1 << 9];
void init() {
	sort(disc + 1, disc + 1 + dcnt);
	t = unique(disc + 1, disc + 1 + dcnt) - disc - 1;
	For(i, 1, n) {
		p[i].l = lower_bound(disc + 1, disc + 1 + t, p[i].l) - disc;
		siz[p[i].l] = disc[p[i].l] - disc[p[i].l-1];
		p[i].r = lower_bound(disc + 1, disc + 1 + t, p[i].r) - disc;
		siz[p[i].r] = disc[p[i].r] - disc[p[i].r-1];
	}
}
signed main()
{
	cin >> n >> m >> K;
	For(i, 1, n)
		p[i].l = read(), p[i].r = read(), disc[++dcnt] = p[i].l, disc[++dcnt] = p[i].r;
	init();
	sort(p + 1, p + 1 + n);
	For(i, 0, K-1) {
		int lst = 0, cnt = 0;
		For(j, 1, n) {
			if(!used[j] && p[j].l > lst) {
				lst = p[j].r; used[j] = 1;
				a[i][++cnt] = j;
				For(k, p[j].l, p[j].r)
					id[i][k] = cnt;
				ed[i][p[j].r] = 1;
			}
		}
	}
	For(i, 1, n)
		assert(used[i] == 1);
	For(j, 1, t)
		For(i, 0, K-1)
			mst[j] |= (1 << i) * (id[i][j] != 0), mask[j] |= (1 << i) * (ed[i][j] != 0);
	For(i, 0, (1 << K) - 1) adt[i] = __builtin_popcount(i) & 1;
	For(i, 1, t) {
		memset(f[i&1], 0, sizeof(f[i&1]));
		For(j, 0, (1 << K) - 1) {
			if((j | mst[i]) != mst[i]) continue;
			int lst = (j & mst[i-1]);
			for(int k = mask[i-1]; k; k = (k - 1) & mask[i-1])
				ckmax(f[i&1][j], f[(i&1)^1][lst | k] + adt[j] * siz[i]);
			ckmax(f[i&1][j], f[(i&1)^1][lst] + adt[j] * siz[i]) ;
		}
//		For(j, 0, (1 << K) - 1) {
//			printf("%d ", f[i&1][j]);
//		}
//		printf("\n");
	}
	int res = 0;
	For(j, 0, (1 << K) - 1) ckmax(res, f[t&1][j]);
	cout << res << endl;
    return 0;
}

 /*
 1 1000 1
1 1000
 */


#pragma GCC optimize(3)
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define reaD() read()
#define pb push_back
#define mkp make_pair
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i, k, j) for(register int i = (k); i >= (j); i--)
#define For(i, k, j) for(register int i = (k); i <= (j); i++)
#define DEBUG fprintf(stderr, "***IAKIOI***\n")
#define CDEBUG cerr << "***IAKIOI***" << endl;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const int P = 998244353; //
using namespace std;
inline void ckmax(int &a, int b) {a = max(a, b);}
inline void ckmin(int &a, int b) {a = min(a, b);}
inline void addmod(int &a, int b) {int t = a + b; a = (t >= P ? t - P : t); }
inline int ksm(int a, int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline int inv(int a) {return ksm(a, P-2);}
inline int read() {
    int num=0,flag=1;char c=' ';
    for(;!isdigit(c);c=getchar()) if(c=='-') flag=-1;
    for(;isdigit(c);num=num*10+c-48,c=getchar());
    return num*flag;
}
const int MAXN = 400005;
struct Line {
	int l, r;
	bool operator < (const Line b) const {return l < b.l;}
}p[MAXN];
int a[9][MAXN], disc[MAXN], dcnt = 0, n, m, K, t, used[MAXN], id[9][MAXN], ed[9][MAXN], mst[MAXN], mask[MAXN], f[2][1 << 9];
void init() {
	sort(disc + 1, disc + 1 + dcnt);
	t = unique(disc + 1, disc + 1 + dcnt) - disc - 1;
	For(i, 1, n) {
		p[i].l = lower_bound(disc + 1, disc + 1 + t, p[i].l) - disc;
		p[i].r = lower_bound(disc + 1, disc + 1 + t, p[i].r) - disc;
	}
}
signed main()
{
	cin >> n >> m >> K;
	For(i, 1, n)
		p[i].l = read(), p[i].r = read(), disc[++dcnt] = p[i].l, disc[++dcnt] = p[i].r;
	init();
	sort(p + 1, p + 1 + n);
	For(i, 0, K-1) {
		int lst = 0, cnt = 0;
		For(j, 1, n) {
			if(!used[j] && p[j].l > lst) {
				lst = p[j].r; used[j] = 1;
				a[i][++cnt] = j;
				For(k, p[j].l, p[j].r)
					id[i][k] = cnt;
				ed[i][p[j].r] = 1;
			}
		}
	}
	For(j, 1, t)
		For(i, 0, K-1)
			mst[j] |= (1 << i) * (id[i][j] != 0), mask[j] |= (1 << i) * (ed[i][j] != 0);
	For(i, 1, t) {
		memset(f[i&1], 0, sizeof(f[i&1]));
		For(j, 0, (1 << K) - 1) {
			if((j | mst[i]) != mst[i]) continue;
			int lst = (j & mst[i-1]);
			for(int k = mask[i-1]; k; k = (k - 1) & mask[i-1]) {
				ckmax(f[i&1][j], f[(i&1)^1][lst | k] + (__builtin_popcount(j) & 1));
			}
			ckmax(f[i&1][j], f[(i&1)^1][lst] + (__builtin_popcount(j) & 1));
		}
//		For(j, 0, (1 << K) - 1) {
//			printf("%d ", f[i&1][j]);
//		}
//		printf("\n");
	}
	int res = 0;
	For(j, 0, (1 << K) - 1) ckmax(res, f[t&1][j]);
	cout << res << endl;
    return 0;
}