#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 8;
int a[MAXN], dp[MAXN][MAXN];
pair<int, int> par[MAXN][MAXN];
int b[10] = {119, 36, 93, 109, 46, 107, 123, 37, 127, 111};
int n, k;
void input();
void solve();
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  input();
  solve();
  return 0;
}
void input() {
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 7; j++) {
      char c;
      cin >> c;
      if (c == '1') a[i] += 1 << j;
    }
}
void solve() {
  memset(dp, -1, sizeof dp);
  dp[0][0] = 0;
  reverse(a, a + n);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= k; j++)
      if (dp[i][j] != -1)
        for (int l = 0; l < 10; l++)
          if (a[i] - (a[i] & b[l]) == 0 &&
              l > dp[i + 1][j + __builtin_popcount(a[i] ^ b[l])]) {
            par[i + 1][j + __builtin_popcount(a[i] ^ b[l])] = {i, j};
            dp[i + 1][j + __builtin_popcount(a[i] ^ b[l])] = l;
          }
  if (dp[n][k] == -1) {
    cout << -1 << endl;
    return;
  }
  int i = n, j = k;
  while (i != 0) {
    cout << dp[i][j];
    pair<int, int> x = par[i][j];
    i = x.first;
    j = x.second;
  }
}
