#include <bits/stdc++.h>
using namespace std;
string s[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
              "1101011", "1101111", "1010010", "1111111", "1111011"};
vector<string> s1;
long long n;
vector<long long> value;
pair<long long, long long> dp[2001][2001];
long long power(long long a, long long b, long long m = 1000000007) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long res = power(a, b / 2, m);
  res = (res * res) % m;
  if (b & 1) res = (res * a) % m;
  return res;
}
long long modinv(long long a) { return power(a, 1000000007 - 2); }
long long check(string a, string b) {
  long long cnt = 0;
  for (long long i = 0; i < 7; i++) {
    if (a[i] == '1' && b[i] == '0') return 2001;
    if (a[i] == '0' && b[i] == '1') cnt++;
  }
  return cnt;
}
bool fun(long long idx, long long k) {
  if (k < 0) return false;
  if (idx == n) return (k == 0);
  pair<long long, long long> &ans = dp[idx][k];
  if (ans.first != -1) return (ans.first != -2);
  for (long long i = 9; i >= 0; i--) {
    long long x = check(s1[idx], s[i]);
    if (fun(idx + 1, k - x)) {
      ans = {i, x};
      return true;
    }
  }
  ans = {-2, -2};
  return false;
}
void solve() {
  long long i, j, sum = 0, k;
  cin >> n >> k;
  s1 = vector<string>(n);
  for (i = 0; i < n; i++) cin >> s1[i];
  for (i = 0; i < n; i++)
    for (j = 0; j <= k; j++) dp[i][j] = {-1, -1};
  if (!fun(0, k)) {
    cout << "-1"
         << "\n";
    return;
  }
  for (i = 0; i < n; i++) {
    cout << dp[i][k].first;
    k -= dp[i][k].second;
  }
  cout << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) solve();
  return 0;
}
