#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long int digits[] = {0b1110111, 0b0010010, 0b1011101, 0b1011011,
                          0b0111010, 0b1101011, 0b1101111, 0b1010010,
                          0b1111111, 0b1111011};
long long int look[200];
long long int pre[200][10];
void add_segs(long long int dig, long long int segs) {
  for (long long int mask = 0; mask < 128; ++mask) {
    if (__builtin_popcount(mask) != segs) continue;
    if (mask & dig) continue;
    long long int nmask = mask | dig;
    pre[dig][segs] = max(pre[dig][segs], look[nmask]);
  }
}
pair<long long int, long long int> dp[2010][2010];
long long int kval[2010][2010];
long long int numks[2010];
long long int a[2010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(look, -1, sizeof look);
  memset(pre, -1, sizeof pre);
  for (long long int i = 0; i < 10; ++i) {
    look[digits[i]] = i;
  }
  for (long long int dig = 0; dig < 128; ++dig) {
    for (long long int segs = 0; segs <= 7; ++segs) {
      add_segs(dig, segs);
    }
  }
  long long int n;
  cin >> n;
  long long int K;
  cin >> K;
  for (long long int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    char *ptr;
    a[i] = strtoll(s.data(), &ptr, 2);
  }
  memset(dp, -1, sizeof dp);
  dp[0][K] = {0, 0};
  kval[0][0] = K;
  numks[0] = 1;
  for (long long int i = 0; i < n; ++i) {
    for (long long int j = 0; j < numks[i]; ++j) {
      long long int k = kval[i][j];
      if (dp[i][k].first == -1) continue;
      for (long long int segs = 0; segs <= min(7ll, k); ++segs) {
        long long int nd = pre[a[i]][segs];
        if (nd == -1) continue;
        dp[i + 1][k - segs] = max(dp[i + 1][k - segs], {j, nd});
      }
    }
    vector<pair<pair<long long int, long long int>, long long int>> ks;
    for (long long int k = 0; k <= K; ++k) {
      if (dp[i + 1][k].first != -1) ks.push_back({dp[i + 1][k], k});
    }
    sort(ks.begin(), ks.end());
    numks[i + 1] = ks.size();
    for (long long int j = 0; j < ks.size(); ++j) {
      kval[i + 1][j] = ks[j].second;
    }
  }
  if (dp[n][0].first == -1)
    cout << -1 << endl;
  else {
    long long int k = 0;
    long long int i = n;
    string ans = "";
    while (i) {
      ans += ('0' + dp[i][k].second);
      k = kval[i - 1][dp[i][k].first];
      --i;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
  }
}
