#include <bits/stdc++.h>
using namespace std;
int k, n;
string num[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                  "1101011", "1101111", "1010010", "1111111", "1111011"};
string a[2005];
int mem[2005][2005];
bool dp(int i, int rem) {
  if (i == n) {
    if (rem == 0) return mem[i][rem] = 1;
    return mem[i][rem] = 0;
  }
  if (mem[i][rem] != -1) return mem[i][rem];
  bool ret = 0;
  for (int j = 9; j >= 0; j--) {
    int dif = 0;
    bool bla = 0;
    for (int h = 0; h < 7; h++) {
      if (num[j][h] == '1' && a[i][h] == '0') dif++;
      if (num[j][h] == '0' && a[i][h] == '1') bla = 1;
    }
    if (!bla && rem - dif >= 0) {
      ret |= dp(i + 1, rem - dif);
    }
  }
  return mem[i][rem] = ret;
}
string s;
void path(int i, int rem) {
  if (i == n) return;
  int cur = mem[i][rem];
  for (int j = 9; j >= 0; j--) {
    int dif = 0;
    bool bla = 0;
    for (int h = 0; h < 7; h++) {
      if (num[j][h] == '1' && a[i][h] == '0') dif++;
      if (num[j][h] == '0' && a[i][h] == '1') bla = 1;
    }
    if (!bla) {
      if (dp(i + 1, rem - dif) == cur) {
        s += '0' + j;
        path(i + 1, rem - dif);
        return;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(mem, -1, sizeof mem);
  bool ans = dp(0, k);
  if (!ans) {
    cout << -1 << endl;
    return 0;
  } else {
    path(0, k);
    cout << s << endl;
  }
  return 0;
}
