#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const xn=25;
int n,a[xn],b[xn],ansl,ansr,sta[1<<20],top;
struct N{
int l,r;
bool operator < (const N &y) const
{return l==y.l?r<y.r:l<y.l;}//
}f[1<<20];
int rd()
while(ch>='0'&&ch<='9')ret=(ret<<3)+(ret<<1)+ch-'0',ch=getchar();
return f?ret:-ret;
}
void update(int x,int y)
int main()
int mx=(1<<tot);
for(int i=0;i<mx;i++)
for(int j=1;j<=tot;j++)
sort(f,f+mx);
for(int i=0;i<mx;i++)
{
while(top&&f[sta[top]].r<f[i].r)top--;
sta[++top]=i;
}
ansl=1e9; ansr=1e9;
for(int i=1;i<top;i++)update(f[sta[i]].l+1,f[sta[i+1]].r+1);
printf("%d
%d
",ansl+pl,ansr+pr);
return 0;
}