#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
map<long long, long long> m;
long long p[N];
int main() {
  int n, k, a, b, c, d, i, j;
  char ch;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++) {
    scanf("%d%c%d%c%d%c%d", &a, &ch, &b, &ch, &c, &ch, &d, &ch);
    long long x = 256;
    p[i] = a * x * x * x + b * x * x + c * x + d;
  }
  long long res = -1;
  long long now = 0;
  for (i = 31; i >= 0; i--) {
    now += ((1ll) << (i));
    m.clear();
    for (j = 1; j <= n; j++) m[p[j] & now] = 1;
    if (m.size() == k) {
      res = now;
      break;
    }
  }
  if (res == -1)
    printf("-1\n");
  else {
    d = res % 256;
    res /= 256;
    c = res % 256;
    res /= 256;
    b = res % 256;
    res /= 256;
    a = res % 256;
    printf("%d.%d.%d.%d\n", a, b, c, d);
  }
}
