#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n;
int memo[2048][2048];
vector<int> v;
int sticks[10] = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123};
int go(int i, int k) {
  if (i == n) {
    if (k != 0) {
      return -2;
    }
    return 0;
  }
  if (memo[i][k] != -1) {
    return memo[i][k];
  }
  for (int j = 9; j >= 0; --j) {
    if ((v[i] | sticks[j]) ^ sticks[j]) {
      continue;
    }
    int required = __builtin_popcount(sticks[j] - v[i]);
    if (required > k) {
      continue;
    }
    if (go(i + 1, k - required) != -2) {
      memo[i][k] = j;
      break;
    }
  }
  if (memo[i][k] == -1) {
    memo[i][k] = -2;
  }
  return memo[i][k];
}
int main(void) {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  memset(memo, -1, sizeof(memo));
  int k;
  string digit;
  auto b2d = [](int a, char b) { return a * 2 + (b - '0'); };
  cin >> n >> k;
  v.resize(n);
  for (int i = 0; i < (int)(n); i++) {
    cin >> digit;
    v[i] = accumulate(digit.begin(), digit.end(), 0, b2d);
  }
  if (go(0, k) == -2) {
    cout << -1 << '\n';
  } else {
    int x = k;
    for (int i = 0; i < (int)(n); i++) {
      int digit = memo[i][x];
      cout << digit;
      x -= __builtin_popcount(sticks[digit] - v[i]);
    }
    cout << '\n';
  }
  return 0;
}
