#include <bits/stdc++.h>
using namespace std;
template <class T, class T1>
int chkmin(T &x, const T1 &y) {
  return x > y ? x = y, 1 : 0;
}
template <class T, class T1>
int chkmax(T &x, const T1 &y) {
  return x < y ? x = y, 1 : 0;
}
const int MAXN = (1 << 11);
string _d[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                 "1101011", "1101111", "1010010", "1111111", "1111011"};
int d[10];
int n, k;
string _s[MAXN];
int s[MAXN];
void read() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> _s[i];
    s[i] = 0;
    for (char c : _s[i]) {
      s[i] = (s[i] << 1) | (c - '0');
    }
  }
}
int dp[MAXN][MAXN];
int popcnt[MAXN];
int rec(int pos, int k) {
  if (k < 0) return 0;
  if (pos == n) {
    return k == 0;
  }
  int &memo = dp[pos][k];
  if (memo != -1) {
    return memo;
  }
  memo = 0;
  for (int new_d = 0; new_d <= 9; new_d++) {
    if ((d[new_d] & s[pos]) == s[pos] &&
        rec(pos + 1, k - popcnt[s[pos] ^ d[new_d]])) {
      memo = 1;
    }
  }
  return memo;
}
void solve() {
  for (int i = 1; i < MAXN; i++) {
    popcnt[i] = (popcnt[i >> 1]) + (i & 1);
  }
  for (int i = 0; i < 10; i++) {
    d[i] = 0;
    for (char c : _d[i]) {
      d[i] = (d[i] << 1) | (c - '0');
    }
  }
  memset(dp, -1, sizeof(dp));
  if (!rec(0, k))
    cout << -1 << '\n';
  else {
    string ans;
    for (int pos = 0; pos < n; pos++) {
      for (int new_d = 9; new_d >= 0; new_d--) {
        if ((d[new_d] & s[pos]) == s[pos] &&
            rec(pos + 1, k - popcnt[s[pos] ^ d[new_d]])) {
          ans.push_back('0' + new_d);
          k -= popcnt[s[pos] ^ d[new_d]];
          break;
        }
      }
    }
    cout << ans << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}
