#include<iostream>
#include<string>
#include<cmath>
bool check(std::string n){
char wave[2];
wave[0]=n[0];
wave[1]=n[1];
for(std::string::size_type i=2;i<n.size();++i)
if(n[i]!=wave[i%2])
return false;
return true;
}
long log_(long m,long n){//base: m
return std::log(n)/std::log(m);
}
std::string transfer(long raw,long decimal){
if(decimal==10)
return std::to_string(raw);
else{
std::string res{};
long tmp{raw};
long exp,lstexp{0};
while((exp=log_(decimal,tmp))!=0){
if(lstexp==exp and lstexp!=0){
res.back()+=1;
}
else{
for(long i=0;i<lstexp-exp-1;++i)
res.push_back('0');
res.push_back('1');
}
tmp-=std::pow(decimal,exp);
lstexp=exp;
if(tmp==0)
return res;
}
for(long i=0;i<lstexp-exp-1;++i)
res.push_back('0');
res.push_back(tmp+'0');
return res;
}
}
long l,r,L,R,k;
int main(){
std::cin>>l>>r>>L>>R>>k;
for(long i=L;i<=R;++i){
if(not check(transfer(i,10)))continue;
long cnt{};
for(long dec=l;dec<=r and cnt<k;++dec){
if(check(transfer(i,dec))){
++cnt;
}
}
if(cnt==k)
std::cout<<i<<std::endl;
}
return 0;
}
orz