// LVJ submission #65af2abfd14038f289ef5963@1705978560317
#include<bits/stdc++.h>
#define gc getchar()
#define ll unsigned
using namespace std;
int n,k;
ll A,b,c,d,ans=-1;
ll a[100010];
map<ll,bool> mp;
int main() {
cin>>n>>k;
for(int i=1; i<=n; i++) {
cin>>A,gc;
cin>>b,gc;
cin>>c,gc;
cin>>d;
a[i]=(A<<24)+(b<<16)+(c<<8)+d;
}
ll now=UINT_MAX;
for(int i=1; i<=31; i++) {
now-=(1<<i-1);
int cnt=0;
mp.clear();
for(int j=1; j<=n; j++) if(!mp[now&a[j]]) mp[now&a[j]]=1,cnt++;
if(cnt==k) ans=now;
}
if(ans==-1) cout<<"-1";
else cout<<((ans>>24))<<"."<<((ans>>16)&255)<<"."<<((ans>>8)&255)<<"."<<(ans&255);
return 0;
}
1708B - Difference of GCDs | 863A - Quasi-palindrome |
1478A - Nezzar and Colorful Balls | 1581B - Diameter of Graph |
404A - Valera and X | 908A - New Year and Counting Cards |
146A - Lucky Ticket | 1594C - Make Them Equal |
1676A - Lucky | 1700B - Palindromic Numbers |
702C - Cellular Network | 1672C - Unequal Array |
1706C - Qpwoeirut And The City | 1697A - Parkway Walk |
1505B - DMCA | 478B - Random Teams |
1705C - Mark and His Unfinished Essay | 1401C - Mere Array |
1613B - Absent Remainder | 1536B - Prinzessin der Verurteilung |
1699B - Almost Ternary Matrix | 1545A - AquaMoon and Strange Sort |
538B - Quasi Binary | 424A - Squats |
1703A - YES or YES | 494A - Treasure |
48B - Land Lot | 835A - Key races |
1622C - Set or Decrease | 1682A - Palindromic Indices |