The problem uses a simplified TCP/IP address model, please make sure you've read the statement attentively.

Polycarpus has found a job, he is a system administrator. One day he came across n IP addresses. Each IP address is a 32 bit number, represented as a group of four 8-bit numbers (without leading zeroes), separated by dots. For example, the record 0.255.1.123 shows a correct IP address and records 0.256.1.123 and 0.255.1.01 do not. In this problem an arbitrary group of four 8-bit numbers is a correct IP address.

Having worked as an administrator for some time, Polycarpus learned that if you know the IP address, you can use the subnet mask to get the address of the network that has this IP addess.

The subnet mask is an IP address that has the following property: if we write this IP address as a 32 bit string, that it is representable as "11...11000..000". In other words, the subnet mask first has one or more one bits, and then one or more zero bits (overall there are 32 bits). For example, the IP address 2.0.0.0 is not a correct subnet mask as its 32-bit record looks as 00000010000000000000000000000000.

To get the network address of the IP address, you need to perform the operation of the bitwise "and" of the IP address and the subnet mask. For example, if the subnet mask is 255.192.0.0, and the IP address is 192.168.1.2, then the network address equals 192.128.0.0. In the bitwise "and" the result has a bit that equals 1 if and only if both operands have corresponding bits equal to one.

Now Polycarpus wants to find all networks to which his IP addresses belong. Unfortunately, Polycarpus lost subnet mask. Fortunately, Polycarpus remembers that his IP addresses belonged to exactly k distinct networks. Help Polycarpus find the subnet mask, such that his IP addresses will belong to exactly k distinct networks. If there are several such subnet masks, find the one whose bit record contains the least number of ones. If such subnet mask do not exist, say so.

Input

The first line contains two integers, n and k (1 ≤ k ≤ n ≤ 105) — the number of IP addresses and networks. The next n lines contain the IP addresses. It is guaranteed that all IP addresses are distinct.

Output

In a single line print the IP address of the subnet mask in the format that is described in the statement, if the required subnet mask exists. Otherwise, print -1.

Examples

Input

5 3
0.0.0.1
0.1.1.2
0.0.2.1
0.1.1.0
0.0.2.3


Output

255.255.254.0

Input

5 2
0.0.0.1
0.1.1.2
0.0.2.1
0.1.1.0
0.0.2.3


Output

255.255.0.0

Input

2 1
255.0.0.1
0.0.0.2


Output

-1
#include <bits/stdc++.h>
using namespace std;
struct ip {
  int x1, x2, x3, x4;
  ip(int X1 = 0, int X2 = 0, int X3 = 0, int X4 = 0) {
    x1 = X1;
    x2 = X2;
    x3 = X3;
    x4 = X4;
  }
};
string its(int a) {
  string ans = "";
  if (a == 0) return "00000000";
  while (a) {
    ans = (char)('0' + (a % 2)) + ans;
    a /= 2;
  }
  while (ans.size() < 8) ans = '0' + ans;
  return ans;
}
string ip_to_bin(ip a) {
  return (its(a.x1) + its(a.x2) + its(a.x3) + its(a.x4));
}
int sti(string S) {
  int ans = 0;
  int st = 1;
  for (int i = S.size() - 1; i >= 0; i--) {
    ans += (S[i] - '0') * st;
    st *= 2;
  }
  return ans;
}
ip str_to_ip(string S) {
  string S1 = "";
  string S2 = "";
  string S3 = "";
  string S4 = "";
  for (int i = 0; i < 32; i++) {
    if (i / 8 == 0)
      S1 += S[i];
    else if (i / 8 == 1)
      S2 += S[i];
    else if (i / 8 == 2)
      S3 += S[i];
    else
      S4 += S[i];
  }
  return (ip(sti(S1), sti(S2), sti(S3), sti(S4)));
}
string bit(string a, string b) {
  string ans = "";
  for (int i = 0; i < a.size(); i++) {
    if (a[i] == b[i] && a[i] == '1')
      ans += '1';
    else
      ans += '0';
  }
  return ans;
}
int main() {
  int n, k;
  cin >> n >> k;
  string A[n];
  char c;
  for (int i = 0; i < n; i++) {
    int x1, x2, x3, x4;
    scanf("%d.%d.%d.%d", &x1, &x2, &x3, &x4);
    A[i] = ip_to_bin(ip(x1, x2, x3, x4));
  }
  string mask = "00000000000000000000000000000000";
  string bit1[n];
  for (int i = 0; i < n; i++) {
    bit1[i] = bit(mask, A[i]);
  }
  for (int i = 0; i < 31; i++) {
    mask[i] = '1';
    set<string> Set;
    for (int j = 0; j < n; j++) {
      if (A[j][i] == mask[i] && mask[i] == '1')
        bit1[j][i] = '1';
      else
        bit1[j][i] = '0';
      Set.insert(bit1[j]);
    }
    if (Set.size() == k) {
      ip ip = str_to_ip(mask);
      cout << ip.x1 << "." << ip.x2 << "." << ip.x3 << "." << ip.x4 << endl;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
