#include<iostream>
#include<fstream>
using namespace std;
int main(){
int x,v[11]={0},nr=0;
ifstream f("bac.txt");
while(f>>x){
int vx[11]={0};
do{
if(vx[x%10]!=1)
v[x%10]++;
vx[x%10]=1;
x/=10;
}while(x!=0);
nr++;
}
for(int i=9;i>=0;i--)
if(v[i]==nr){
cout<<i;
return 0;
}
cout<<"Nu exista.";
return 0;
}