#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
vector<int64_t> dig = {0b1110111, 0b0010010, 0b1011101, 0b1011011, 0b0111010,
                       0b1101011, 0b1101111, 0b1010010, 0b1111111, 0b1111011};
int32_t main() {
  ios_base::sync_with_stdio(false);
  int64_t n, k;
  cin >> n >> k;
  vector<int64_t> v(n);
  vector<vector<int64_t>> d(n, vector<int64_t>(10, -1));
  for (int64_t i = 0; i < n; ++i) {
    int64_t a = 0;
    for (int64_t j = 6; j >= 0; --j) {
      char c;
      cin >> c;
      a |= (c - '0') << j;
    }
    v[i] = a;
    for (int64_t j = 0; j < 10; ++j) {
      if ((a | dig[j]) != dig[j]) {
        continue;
      }
      d[i][j] = __builtin_popcount(dig[j]) - __builtin_popcount(a);
    }
  }
  vector<vector<pair<int64_t, int64_t>>> from(
      n + 1, vector<pair<int64_t, int64_t>>(k + 7, {-1, -1}));
  vector<int64_t> priority = {k};
  vector<char> ch(k + 7);
  for (int64_t i = 0; i < n; ++i) {
    for (int64_t j = 0; j < k + 7; ++j) {
      ch[j] = false;
    }
    vector<int64_t> new_priority;
    for (int64_t e = 0; e < priority.size(); ++e) {
      int64_t j = priority[e];
      for (int64_t t = 9; t >= 0; --t) {
        if (d[i][t] == -1) {
          continue;
        }
        int64_t u = d[i][t];
        if (u > j) {
          continue;
        }
        if (ch[j - u]) {
          continue;
        }
        from[i + 1][j - u] = {j, t};
        ch[j - u] = true;
        new_priority.push_back(j - u);
      }
    }
    priority = new_priority;
  }
  if (from[n][0].first == -1) {
    cout << -1;
    return 0;
  }
  int64_t cur = 0;
  vector<int64_t> ans;
  for (int64_t i = n; i > 0; --i) {
    ans.push_back(from[i][cur].second);
    cur = from[i][cur].first;
  }
  for (int64_t i = n - 1; i >= 0; --i) {
    cout << ans[i];
  }
}
