#include <bits/stdc++.h>
using namespace std;
long long T = 1;
long long n, k;
string di[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
               "1101011", "1101111", "1010010", "1111111", "1111011"};
long long A[2002][20];
long long dp[2002][2002];
map<string, long long> mp;
long long rec(long long i, long long m) {
  if (m < 0) return -1e9;
  if (m == 0 && i == n) return 0;
  if (i == n && m != 0) return -1e9;
  if (dp[i][m] != -1) return dp[i][m];
  long long num = -1e18;
  for (long long j = 9; j >= 0; j--) {
    if (rec(i + 1, m - A[i][j]) >= 0) {
      num = max(num, j);
      break;
    }
  }
  return dp[i][m] = num;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  for (long long i = 0; i < 10; i++) mp[di[i]] = i;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (long long k = 0; k < 10; k++) {
      long long cost = 0;
      for (long long j = 0; j < s.size(); j++)
        if (s[j] != di[k][j] && s[j] == '0')
          cost++;
        else if (s[j] != di[k][j])
          cost = 1e12;
      A[i][k] = cost;
    }
  }
  memset(dp, -1, sizeof dp);
  if (rec(0, k) >= 0) {
    long long m = k;
    for (long long i = 0; i < n; i++) {
      cout << dp[i][k];
      k -= A[i][dp[i][k]];
    }
  } else
    cout << -1;
}
