#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<vector<long long>> opt(2000, vector<long long>(2001, -2));
vector<string> nums({"1110111", "0010010", "1011101", "1011011", "0111010",
                     "1101011", "1101111", "1010010", "1111111", "1111011"});
int extra(string &source, string &destination) {
  int count = 0;
  for (int i = 0; i < 7; i++) {
    if (source[i] == '0') {
      if (destination[i] == '1') {
        count++;
      }
    } else {
      if (destination[i] == '0') {
        return -1;
      }
    }
  }
  return count;
}
long long dp(int i, int j, vector<string> &board) {
  if (j < 0) return -1;
  if (i >= n) {
    if (j > 0) return -1;
    return 0;
  }
  if (opt[i][j] != -2) return opt[i][j];
  long long max_val = -1;
  for (int l = 9; l >= 0; --l) {
    int val = extra(board[i], nums[l]);
    if (val >= 0) {
      long long new_val = dp(i + 1, j - val, board);
      if (new_val >= 0) {
        max_val = l;
        break;
      }
    }
  }
  opt[i][j] = max_val;
  return max_val;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> k;
  vector<string> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int res = dp(0, k, a);
  if (res == -1)
    cout << -1 << endl;
  else {
    for (int i = 0; i < n; ++i) {
      cout << opt[i][k];
      int extra_val = extra(a[i], nums[opt[i][k]]);
      k = k - extra_val;
    }
    cout << endl;
  }
  return 0;
}
