#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& dbg_print(ostream& out, const T& dbg_t) {
  out << "[";
  for (auto i : dbg_t) out << i << ", ";
  out << "]";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const set<T>& dbg_t) {
  return dbg_print(out, dbg_t);
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& dbg_t) {
  return dbg_print(out, dbg_t);
}
template <typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T>& rhs) {
  out << "(" << rhs.first << "," << rhs.second << ")";
  return out;
}
template <typename T>
void max_e(T& aaa, const T& bbb) {
  aaa = max(aaa, bbb);
}
template <typename T>
void min_e(T& aaa, const T& bbb) {
  aaa = min(aaa, bbb);
}
string masks[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                  "1101011", "1101111", "1010010", "1111111", "1111011"};
int n, k;
vector<string> board;
vector<vector<bool>> dp;
int reach(string from, string to) {
  int cnt = 0;
  for (int i = 0; i < int(((int)((from).size()))); ++i) {
    if (from[i] == '1' && to[i] == '0') return -1;
    if (from[i] == '0' && to[i] == '1') cnt++;
  }
  return cnt;
}
string solve() {
  dp.assign(n + 1, vector<bool>(k + 1, false));
  dp[n][0] = true;
  for (int i = n - 1; i >= 0; i--) {
    for (int digit = 0; digit < int(10); ++digit) {
      int d = reach(board[i], masks[digit]);
      if (d == -1) continue;
      for (int j = (d); j < (k + 1); ++j)
        if (dp[i + 1][j - d]) dp[i][j] = true;
    }
  }
  if (!dp[0][k]) return "-1";
  string result;
  int remaining = k;
  for (int i = 0; i < int(n); ++i) {
    for (int digit = 9; digit >= 0; digit--) {
      int d = reach(board[i], masks[digit]);
      if (d == -1) continue;
      if (d > remaining) continue;
      if (dp[i + 1][remaining - d]) {
        result += (char)('0' + digit);
        remaining -= d;
        break;
      }
    }
    assert(((int)((result).size())) == i + 1);
  }
  return result;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int z = 1;
  while (z--) {
    cin >> n >> k;
    board.assign(n, "");
    for (int i = 0; i < int(n); ++i) cin >> board[i];
    cout << solve() << endl;
  }
  return 0;
}
