#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 3;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
bool dp[N][N];
bool ok[N][10];
int cnt[N][10];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string t[10];
  t[0] = "1110111";
  t[1] = "0010010";
  t[2] = "1011101";
  t[3] = "1011011";
  t[4] = "0111010";
  t[5] = "1101011";
  t[6] = "1101111";
  t[7] = "1010010";
  t[8] = "1111111";
  t[9] = "1111011";
  int n, k;
  cin >> n >> k;
  string s[n + 4];
  for (int i = 1; i <= n; ++i) cin >> s[i];
  for (int i = 1; i <= n; ++i) {
    for (int l = 0; l <= 9; ++l) {
      ok[i][l] = 1;
      for (int p = 0; p <= 6; ++p) {
        if (t[l][p] == '0' && s[i][p] == '1') ok[i][l] = 0;
        if (t[l][p] == '1' && s[i][p] == '0') ++cnt[i][l];
      }
    }
  }
  dp[n + 1][0] = 1;
  for (int i = n; i >= 1; --i) {
    for (int l = 0; l <= 9; ++l) {
      if (!ok[i][l]) continue;
      for (int j = cnt[i][l]; j <= k; ++j)
        dp[i][j] = max(dp[i][j], dp[i + 1][j - cnt[i][l]]);
    }
  }
  if (!dp[1][k]) return cout << -1, 0;
  string ans = "";
  for (int i = 1; i <= n; ++i) {
    for (int l = 9; l >= 0; --l) {
      if (ok[i][l] && k >= cnt[i][l] && dp[i + 1][k - cnt[i][l]]) {
        ans += char(l + '0');
        k -= cnt[i][l];
        break;
      }
    }
  }
  cout << ans;
  return 0;
}
