#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
using namespace std;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
template <class T, class U>
inline void checkmin(T &x, U y) {
  if (y < x) x = y;
}
template <class T, class U>
inline void checkmax(T &x, U y) {
  if (y > x) x = y;
}
template <class T, class U>
inline bool ifmax(T &x, U y) {
  if (y > x) return x = y, true;
  return false;
}
template <class T, class U>
inline bool ifmin(T &x, U y) {
  if (y < x) return x = y, true;
  return false;
}
template <class T>
inline void sort(T &a) {
  sort(a.begin(), a.end());
}
template <class T>
inline void rsort(T &a) {
  sort(a.rbegin(), a.rend());
}
template <class T>
inline void reverse(T &a) {
  reverse(a.begin(), a.end());
}
template <class T, class U>
inline istream &operator>>(istream &str, pair<T, U> &p) {
  return str >> p.first >> p.second;
}
template <class T>
inline istream &operator>>(istream &str, vector<T> &a) {
  for (auto &i : a) str >> i;
  return str;
}
template <class T>
inline T sorted(T a) {
  sort(a);
  return a;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  int zero = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 4) | (1 << 5) | (1 << 6);
  int one = (1 << 2) | (1 << 5);
  int two = (1 << 0) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 6);
  int three = (1 << 0) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 6);
  int four = (1 << 1) | (1 << 2) | (1 << 3) | (1 << 5);
  int five = (1 << 0) | (1 << 1) | (1 << 3) | (1 << 5) | (1 << 6);
  int six = (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
  int seven = (1 << 0) | (1 << 2) | (1 << 5);
  int eight = (1 << 7) - 1;
  int nine = eight ^ (1 << 4);
  vector<int> masks = {zero, one, two,   three, four,
                       five, six, seven, eight, nine};
  vector<vector<int>> edge(1 << 7);
  for (int mask = 0; mask < (1 << 7); ++mask)
    for (int j = 9; j >= 0; --j) {
      if ((masks[j] & mask) == mask) edge[mask].push_back(j);
    }
  int n, k;
  cin >> n >> k;
  vector<int> msk(n);
  for (auto &i : msk) {
    string second;
    cin >> second;
    for (int j = 0; j < signed(second.size()); ++j)
      if (second[j] == '1') i |= 1 << j;
  }
  vector<bitset<2001>> dp(n + 1, bitset<2001>());
  dp[n][0] = 1;
  for (int i = n - 1; i >= 0; --i) {
    for (auto x : edge[msk[i]]) {
      int d = __builtin_popcount(masks[x]) - __builtin_popcount(msk[i]);
      dp[i] |= dp[i + 1] << d;
    }
  }
  if (!dp[0][k])
    cout << -1;
  else {
    for (int i = 0; i < n; ++i) {
      for (auto x : edge[msk[i]]) {
        int d = __builtin_popcount(masks[x]) - __builtin_popcount(msk[i]);
        if (k >= d && dp[i + 1][k - d]) {
          cout << x;
          k -= d;
          break;
        }
      }
    }
  }
  return 0;
}
