#include <bits/stdc++.h>
#pragma Optimize("O3")
using namespace std;
int n, x, a, b, y, m, k, total, extra;
vector<int> v;
char c;
int vec[2005];
int digits[15];
int mmi(int nr) {
  int r = (1 << 30) + 100;
  int s;
  bool ok;
  for (int i = 0; i < 10; i++) {
    s = 0;
    ok = true;
    for (int j = 0; j <= 6; j++) {
      if (((nr >> j) & 1) == 1 && ((digits[i] >> j) & 1) == 0) {
        ok = false;
        break;
      }
      if (((nr >> j) & 1) == 0 && ((digits[i] >> j) & 1) == 1) s++;
    }
    if (ok && s < r) r = s;
  }
  return r;
}
int fun(int ii) {
  int s;
  bool ok;
  int nr = v[ii];
  for (int i = 9; i >= 0; i--) {
    s = 0;
    ok = true;
    for (int j = 0; j <= 6; j++) {
      if (((nr >> j) & 1) == 1 && ((digits[i] >> j) & 1) == 0) {
        ok = false;
        break;
      }
      if (((nr >> j) & 1) == 0 && ((digits[i] >> j) & 1) == 1) s++;
    }
    if (ii == n - 1 && s != extra + vec[ii]) ok = false;
    if (ok && s <= extra + vec[ii]) {
      extra -= s - vec[ii];
      return i;
    }
  }
  return -1;
}
int main() {
  digits[0] = 119;
  digits[1] = 18;
  digits[2] = 93;
  digits[3] = 91;
  digits[4] = 58;
  digits[5] = 107;
  digits[6] = 111;
  digits[7] = 82;
  digits[8] = 127;
  digits[9] = 123;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    x = 0;
    for (int j = 6; j >= 0; j--) {
      cin >> c;
      if (c == '1') x = x | (1 << j);
    }
    v.push_back(x);
    vec[i] += mmi(x);
    if (vec[i] == (1 << 30) + 100) {
      cout << -1 << '\n';
      return 0;
    }
    total += vec[i];
  }
  if (total > k) {
    cout << -1 << '\n';
    return 0;
  }
  int i = 0;
  extra = k - total;
  vector<int> ans;
  while (i < n) {
    ans.push_back(fun(i));
    if (ans.back() == -1) {
      cout << -1 << '\n';
      return 0;
    }
    i++;
  }
  for (auto i : ans) cout << i;
  cout << '\n';
  return 0;
}
