#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1.01e9;
const long long infll = (long long)1.01e18;
const long double eps = 1e-9;
const long double pi = acos((long double)-1);
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
const vector<string> nums = {"1110111", "0010010", "1011101", "1011011",
                             "0111010", "1101011", "1101111", "1010010",
                             "1111111", "1111011"};
vector<int> msks;
int getMsk(const string &s) {
  assert(((int)(s).size()) == 7);
  int msk = 0;
  for (int i = 0; i < ((int)(s).size()); i++) {
    if (s[i] == '1') {
      msk |= (1 << i);
    }
  }
  return msk;
}
void precalc() {
  for (int i = 0; i < ((int)(nums).size()); i++) {
    msks.push_back(getMsk(nums[i]));
  }
}
const int maxn = 2005;
char tmp[maxn];
int n, k;
int a[maxn];
bool read() {
  if (scanf("%d%d", &n, &k) < 2) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%s", tmp);
    string s = tmp;
    a[i] = getMsk(s);
  }
  return true;
}
int dp[maxn][maxn];
string ans;
int light(int x, int y) {
  if ((x & y) != x) {
    return -1;
  }
  return __builtin_popcount(y ^ x);
}
void solve() {
  memset(dp, 0, sizeof(dp));
  dp[n][0] = true;
  for (int i = n; i > 0; i--) {
    for (int j = 0; j <= k; j++) {
      auto cur = dp[i][j];
      if (!cur) {
        continue;
      }
      for (int d = 0; d < 10; d++) {
        int x = light(a[i - 1], msks[d]);
        if (x == -1) {
          continue;
        }
        if (j + x <= k) {
          dp[i - 1][j + x] = true;
        }
      }
    }
  }
  if (!dp[0][k]) {
    printf("-1\n");
    return;
  }
  ans = "";
  for (int i = 0, j = k; i < n; i++) {
    for (int d = 9; d >= 0; d--) {
      int x = light(a[i], msks[d]);
      if (x == -1 || x > j || !dp[i + 1][j - x]) {
        continue;
      }
      ans += (char)('0' + d);
      j -= x;
      break;
    }
  }
  printf("%s\n", ans.c_str());
}
int main() {
  precalc();
  while (read()) {
    solve();
  }
  return 0;
}
