#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1.0);
long long mod = 998244353;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
long long prod(long long a, long long b) {
  long long res = 0;
  a %= mod;
  while (b) {
    if (b & 1ll) res = (res + a) % mod;
    a = (2ll * a) % mod;
    b >>= 1ll;
  }
  return res;
}
long long power(long long a, long long b) {
  long long res = 1ll;
  while (b > 0) {
    if (b % 2ll) res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2ll;
  }
  return res;
}
void solve() {
  vector<long long> v{119, 18, 93, 91, 58, 107, 111, 82, 127, 123};
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    string t;
    cin >> t;
    a[i] = stoi(t, 0, 2);
  }
  vector<vector<bool>> possible(n + 1, vector<bool>(k + 1, false));
  possible[n][0] = true;
  for (long long i = n - 1; i >= 0; i--) {
    bool p = false;
    for (long long j = 0; j < 10; j++) {
      if ((a[i] & v[j]) == a[i]) {
        long long d = bitset<60>(v[j]).count();
        d -= bitset<60>(a[i]).count();
        for (long long f = 0; f <= k - d; f++) {
          if (possible[i + 1][f]) {
            possible[i][f + d] = true;
            p = true;
          }
        }
      }
    }
  }
  if (!possible[0][k]) {
    cout << -1 << "\n";
    return;
  }
  long long cur = k;
  vector<long long> ans(n, 0);
  for (long long i = 0; i < n; i++) {
    for (long long j = 9; j >= 0; j--) {
      if ((a[i] & v[j]) == a[i]) {
        long long d = bitset<60>(v[j]).count();
        d -= bitset<60>(a[i]).count();
        if (cur >= d and possible[i + 1][cur - d]) {
          cur -= d;
          ans[i] = j;
          break;
        }
      }
    }
  }
  for (auto e : ans) {
    cout << e;
  }
  cout << "\n";
}
signed main() {
  long long t = 1;
  while (t--) {
    solve();
  }
}
