#include <bits/stdc++.h>
using namespace std;
int book[255];
int f[255][10], g[255][10];
queue<int> q;
void init(int x, int num) {
  memset(book, 0, sizeof(book));
  f[x][0] = num;
  g[x][num] = 0;
  q.push(x);
  book[x] = true;
  while (!q.empty()) {
    int tmp = q.front();
    q.pop();
    for (int i = 0; i <= 6; i++) {
      if (tmp & (1 << i)) {
        if (!book[tmp ^ (1 << i)]) {
          book[tmp ^ (1 << i)] = true;
          q.push(tmp ^ (1 << i));
          g[tmp ^ (1 << i)][num] = g[tmp][num] + 1;
        }
      }
    }
  }
}
char s[10];
int a[2005], ans[2005];
int can[2005][2005];
int main() {
  memset(f, -1, sizeof(f));
  memset(g, -1, sizeof(g));
  init(119, 0);
  init(18, 1);
  init(93, 2);
  init(91, 3);
  init(58, 4);
  init(107, 5);
  init(111, 6);
  init(82, 7);
  init(127, 8);
  init(123, 9);
  for (int i = 1; i <= 7; i++)
    for (int j = 0; j <= 127; j++)
      if (f[j][i - 1] != -1)
        for (int k = 0; k <= 6; k++)
          if (j & (1 << k))
            f[j ^ (1 << k)][i] = max(f[j ^ (1 << k)][i], f[j][i - 1]);
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    int x = 0;
    for (int j = 1; j <= 7; j++) x = x * 2 + s[j] - '0';
    a[i] = x;
  }
  can[n + 1][0] = 1;
  for (int i = n; i; i--)
    for (int j = 0; j <= 7; j++)
      if (f[a[i]][j] != -1)
        for (int p = 0; p <= k; p++)
          if (can[i + 1][p] && p + j <= k) can[i][p + j] = 1;
  int used = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 9; j >= 0; j--) {
      if (g[a[i]][j] != -1 && used + g[a[i]][j] <= k &&
          can[i + 1][k - used - g[a[i]][j]]) {
        used += g[a[i]][j];
        ans[i] = j;
        break;
      }
      if (j == 0) return !printf("-1");
    }
  }
  for (int i = 1; i <= n; i++) printf("%d", ans[i]);
}
