#include <bits/stdc++.h>
using namespace std;
int n, k, dig[10] = {119, 36, 93, 109, 46, 107, 123, 37, 127, 111}, p10,
          cur[2005], vis[2005][2005];
char c;
vector<char> ans;
bool solve(int N, int K) {
  if (K < 0) return false;
  if (N == n && K == 0)
    return true;
  else if (N == n)
    return false;
  if (vis[N][K]) return false;
  for (int i = 9; i >= 0; i--)
    if ((dig[i] | cur[N]) == dig[i]) {
      int d = __builtin_popcount(dig[i] ^ cur[N]);
      ans.push_back('0' + i);
      if (solve(N + 1, K - d)) return true;
      ans.pop_back();
    }
  vis[N][K] = true;
  return false;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 7; j++) scanf(" %c", &c), cur[i] |= (c - '0') << j;
  if (solve(0, k)) {
    for (char a : ans) printf("%c", a);
    printf("\n");
  } else
    printf("-1\n");
}
