#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100005;
const long long maxm = 2005;
int n, k, dp[maxm][maxm];
string s[maxn];
string num[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                  "1101011", "1101111", "1010010", "1111111", "1111011"};
int cal(string s, int c) {
  int i, cnt = 0;
  for (i = 0; i < 7; i++) {
    if (s[i] == '1' && num[c][i] == '0') return -1;
    if (s[i] != num[c][i]) cnt++;
  }
  return cnt;
}
int main() {
  int i, j, l, op, now;
  cin >> n >> k;
  memset(dp, -1, sizeof dp);
  for (i = 1; i <= n; i++) cin >> s[i];
  for (i = n; i >= 1; i--) {
    if (i == n) {
      for (j = 0; j < 10; j++) {
        op = cal(s[i], j);
        if (op == -1) continue;
        dp[n][op] = max(dp[n][op], j);
      }
    } else {
      for (j = 0; j < 10; j++) {
        op = cal(s[i], j);
        if (op == -1) continue;
        for (l = op; l <= k; l++)
          if (dp[i + 1][l - op] != -1) dp[i][l] = j;
      }
    }
  }
  if (dp[1][k] == -1)
    puts("-1");
  else {
    now = k;
    for (i = 1; i <= n; i++) {
      cout << dp[i][now];
      now -= cal(s[i], dp[i][now]);
    }
    puts("");
  }
  return 0;
}
