#include <bits/stdc++.h>
using namespace std;
const long long int INF = LONG_LONG_MAX >> 1;
const long long int NINF = LONG_LONG_MIN / 2;
string number[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                     "1101011", "1101111", "1010010", "1111111", "1111011"};
long long int n, k;
vector<string> digit;
vector<vector<long long int> > cst;
string ans = "";
bool ok = false;
const long long int N = 2005;
bool dp[N][N];
void dfs(long long int pos, long long int sum) {
  if (ok) return;
  if (pos == n) {
    if (sum == 0) ok = true;
    return;
  }
  for (long long int i = 9; i >= 0; i--) {
    if (cst[pos][i] != INF) {
      if (!ok && sum - cst[pos][i] >= 0 && dp[pos][sum - cst[pos][i]] == true) {
        ans[pos] = i + '0';
        dfs(pos + 1, sum - cst[pos][i]);
        dp[pos][sum - cst[pos][i]] = false;
      }
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  digit.resize(n);
  for (string& s : digit) cin >> s;
  cst.resize(n);
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < 10; j++) {
      long long int cnt = 0;
      for (long long int k = 0; k < 7; k++) {
        if (number[j][k] == '1' && digit[i][k] == '0') cnt++;
        if (number[j][k] == '0' && digit[i][k] == '1') {
          cnt = INF;
          break;
        }
      }
      cst[i].push_back(cnt);
    }
  }
  for (long long int i = 0; i < N; i++)
    for (long long int j = 0; j < N; j++) dp[i][j] = true;
  for (long long int i = 0; i < n; i++) ans += " ";
  dfs(0, k);
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
