#include <bits/stdc++.h>
using namespace std;
const int maxn = 2222;
long long v[11], n, k;
bool dp[maxn][maxn];
vector<long long> vt;
long long gbin(string t) {
  long long i, ret = 0;
  for (i = 0; i < 7; i++) {
    if (t[i] == '1') {
      ret += 1 << (6 - i);
    }
  }
  return ret;
}
int main() {
  v[0] = 119, v[1] = 18, v[2] = 93, v[3] = 91, v[4] = 58;
  v[5] = 107, v[6] = 111, v[7] = 82, v[8] = 127, v[9] = 123;
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; i++) {
    string ttt;
    cin >> ttt;
    vt.push_back(gbin(ttt));
  }
  memset(dp, false, sizeof(dp));
  dp[n][0] = true;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j <= k; j++) {
      if (!dp[i + 1][j]) {
        continue;
      }
      for (int l = 9; l >= 0; l--) {
        if ((v[l] & vt[i]) == vt[i]) {
          int ad = __builtin_popcount(v[l] ^ vt[i]);
          dp[i][j + ad] = true;
        }
      }
    }
  }
  if (!dp[0][k]) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 9; j >= 0; j--) {
      if ((v[j] & vt[i]) == vt[i]) {
        int ad = __builtin_popcount(v[j] ^ vt[i]);
        if (k >= ad && dp[i + 1][k - ad]) {
          printf("%d", j);
          k -= ad;
          break;
        }
      }
    }
  }
  cout << endl;
  return 0;
}
