#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
void read(Tp &x) {
  x = 0;
  int fh = 1;
  char ch = 1;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') fh = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= fh;
}
template <typename Tp>
void biread(Tp &x) {
  x = 0;
  int fh = 1;
  char ch = 1;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') fh = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 2 + ch - '0', ch = getchar();
  x *= fh;
}
const int maxn = 2000 + 7;
int eps[10] = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123};
int dis[1 << 7][10], n, k, curr[maxn];
bool acc[maxn][maxn];
int calc(int x, int y) {
  int res = 0;
  while (x) {
    if ((x & 1) && ((y & 1) == 0)) ++res;
    x >>= 1, y >>= 1;
  }
  return res;
}
void Preprocess(void) {
  for (int i = 0; i < (1 << 7); i++) {
    for (int j = 0; j < 10; j++) {
      if ((i & eps[j]) != i)
        dis[i][j] = -1;
      else
        dis[i][j] = calc(eps[j], i);
    }
  }
}
void Init(void) {
  read(n);
  read(k);
  for (int i = 1; i <= n; i++) {
    biread(curr[i]);
  }
}
void Work(void) {
  Preprocess();
  acc[n + 1][0] = true;
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j <= k; j++) {
      if (acc[i + 1][j] == false) continue;
      for (int p = 0; p < 10; p++) {
        if (dis[curr[i]][p] == -1) continue;
        if (j + dis[curr[i]][p] <= k) acc[i][j + dis[curr[i]][p]] = true;
      }
    }
  }
  if (!acc[1][k]) {
    puts("-1");
    return;
  }
  int useup = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 9; j >= 0; j--) {
      if (dis[curr[i]][j] == -1) continue;
      if (dis[curr[i]][j] + useup > k) continue;
      if (acc[i + 1][k - dis[curr[i]][j] - useup]) {
        printf("%d", j);
        useup += dis[curr[i]][j];
        break;
      }
    }
  }
}
int main(void) {
  Init();
  Work();
  return 0;
}
