#include <bits/stdc++.h>
using namespace std;
set<long long> tp;
long long tmp[100002], x, y, z, t;
char ch;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld%c%lld%c%lld%c%lld", &x, &ch, &y, &ch, &z, &ch, &t);
    tmp[i] = t + (1 << 8) * z + (1 << 16) * y + (1 << 24) * x;
  }
  long long sum = 0LL;
  bool mn = false;
  for (int i = 31; i >= 0; i--) {
    sum += (1LL << i);
    tp.clear();
    for (int j = 1; j <= n; j++) {
      tp.insert((tmp[j] & sum));
    }
    if (tp.size() == k) {
      int ans = 0;
      for (int i = 31; i > 23; i--) {
        ans = ans * 2;
        if ((1LL << i) & sum) ans++;
      }
      printf("%d.", ans);
      ans = 0;
      for (int i = 23; i > 15; i--) {
        ans = ans * 2;
        if ((1LL << i) & sum) ans++;
      }
      printf("%d.", ans);
      ans = 0;
      for (int i = 15; i > 7; i--) {
        ans = ans * 2;
        if ((1LL << i) & sum) ans++;
      }
      printf("%d.", ans);
      ans = 0;
      for (int i = 7; i >= 0; i--) {
        ans = ans * 2;
        if ((1LL << i) & sum) ans++;
      }
      printf("%d", ans);
      ans = 0;
      mn = true;
      break;
    }
  }
  if (mn == false) printf("-1");
  return 0;
}
