#include <bits/stdc++.h>
using namespace std;
const long long MOD2 = 998244353;
const long long MOD = 1e9 + 7;
const long long MAX = 1e5 + 7;
const long long inf = 1e18L + 5;
const double pi = 3.14159265358979323846;
long long fpow(long long n, long long m) {
  long long res = 1;
  while (m > 0) {
    if (m & 1) {
      res *= n;
    }
    m /= 2;
    n *= n;
  }
  return res;
}
const long long nax = 1e5 + 5;
bool dp[2005][2005];
vector<pair<long long, long long> > poss[2005];
void solve() {
  long long n, k;
  cin >> n >> k;
  string num[n];
  string digits[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                     "1101011", "1101111", "1010010", "1111111", "1111011"};
  for (long long i = 0; i < n; i++) cin >> num[i];
  long long diff;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 10; j++) {
      diff = 0;
      for (long long k = 0; k < 7; k++) {
        diff += (num[i][k] != digits[j][k]);
        if (num[i][k] == '1' && digits[j][k] != '1') {
          break;
        }
        if (k == 6) {
          poss[i].push_back(make_pair(j, diff));
        }
      }
    }
  }
  dp[n][k] = true;
  for (int i = n; i > 0; --i) {
    for (int j = 0; j < 2001; ++j) {
      if (dp[i][j]) {
        for (auto t : poss[i - 1]) {
          if (t.second <= j) dp[i - 1][j - t.second] = true;
        }
      }
    }
  }
  if (!dp[0][0]) {
    cout << -1;
    return;
  }
  long long temp, curr = 0, val;
  string ans = "";
  for (int i = 0; i < n; ++i) {
    temp = -1;
    val = 0;
    for (auto t : poss[i]) {
      if (curr + t.second <= k && dp[i + 1][curr + t.second]) {
        if (t.first > temp) temp = t.first, val = t.second;
      }
    }
    curr += val;
    ans += char(temp + '0');
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
