#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long N = 2e3 + 7;
long long int dp[N][N], upd[N][N];
string num[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                  "1101011", "1101111", "1010010", "1111111", "1111011"};
string s[N];
long long int ok(long long int id, long long int nm) {
  long long int ret = 0;
  for (long long int i = 0; i < (long long)((s[id]).size()); i++) {
    if (s[id][i] == '1' && num[nm][i] == '0') return -1;
    ret += (s[id][i] != num[nm][i]);
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k, i, j, r, x, y;
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> s[i];
  memset(dp, -63, sizeof dp);
  for (i = 0; i < 10; i++) {
    x = ok(n, i);
    if (x != -1) dp[n][x] = max(dp[n][x], i);
  }
  for (i = n - 1; i > 0; i--) {
    for (j = 0; j <= k; j++) {
      for (r = 0; r < 10; r++) {
        x = ok(i, r);
        if (x != -1 && x <= j) {
          if (dp[i + 1][j - x] > -1) {
            dp[i][j] = r;
            upd[i][j] = j - x;
          }
        }
      }
    }
  }
  j = k, i = 1;
  if (dp[1][j] < 0) return cout << -1 << endl, 0;
  while (i <= n) {
    cout << dp[i][j];
    j = upd[i][j];
    i++;
  }
  cout << endl;
  return 0;
}
