#include <bits/stdc++.h>
using namespace std;
set<int> s;
int a[100005][35], b[100005];
int n, k;
int main() {
  char tmp;
  int use;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 4; j++) {
      cin >> use;
      if (j != 4) cin >> tmp;
      int l = 0;
      while (use != 0) {
        l++;
        a[i][(j - 1) * 8 + 8 - l] = use % 2;
        use /= 2;
      }
    }
    b[i] = a[i][0];
    s.insert(b[i]);
  }
  int i;
  for (i = 1; i <= 31; i++) {
    if (s.size() >= k) break;
    s.clear();
    for (int j = 1; j <= n; j++) {
      b[j] = b[j] * 2 + a[j][i];
      s.insert(b[j]);
    }
  }
  if (s.size() != k) {
    cout << -1 << endl;
    return 0;
  }
  int l = 0, j;
  for (j = 0; j <= 31; j++) {
    l = l * 2 + (j < i);
    if (j % 8 == 7) {
      cout << l;
      if (j != 31) cout << ".";
      l = 0;
    }
  }
  return 0;
}
