#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char e = getchar();
  for (; e < '0' || e > '9'; e = getchar())
    ;
  for (; e >= '0' && e <= '9'; e = getchar()) x = x * 2 + e - '0';
  return x;
}
const int N = 2005;
int a[N], to[12];
const int inf = 1 << 30;
inline int dist(int x, int y) {
  int ans = 0;
  for (int i = 0; i < 7; i++)
    if (x & (1 << i)) {
      if (!(y & (1 << i))) return inf;
    } else if (y & (1 << i))
      ans++;
  return ans;
}
int sum[N];
vector<int> ans;
bool vis[2005][8], f[2005][2005 * 7];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) a[i] = read();
  to[0] = 119, to[1] = 18, to[2] = 93, to[3] = 91, to[4] = 58, to[5] = 107,
  to[6] = 111, to[7] = 82, to[8] = 127, to[9] = 123;
  for (int i = 1; i <= n; i++) {
    bool flag = false;
    for (int j = 0; j <= 9; j++)
      if (dist(a[i], to[j]) <= 7) vis[i][dist(a[i], to[j])] = true, flag = true;
    if (!flag) {
      puts("-1");
      return 0;
    }
  }
  f[n + 1][0] = true;
  for (int i = n; i >= 1; i--)
    for (int j = 0; j <= 7; j++)
      if (vis[i][j])
        for (int k = (n - i) * 7; k >= 0; k--) f[i][k + j] |= f[i + 1][k];
  for (int i = 1; i <= n; i++) {
    bool flag = false;
    for (int j = 9; j >= 0; j--)
      if (dist(a[i], to[j]) <= 7 && f[i + 1][m - dist(a[i], to[j])]) {
        m -= dist(a[i], to[j]);
        ans.push_back(j);
        flag = true;
        break;
      }
    if (!flag) {
      puts("-1");
      return 0;
    }
  }
  for (int i = 0; i < ans.size(); i++) printf("%d", ans[i]);
  return 0;
}
