#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int get_distance(const vector<vector<int>> &segments, const string &digit,
                 int which) {
  int ret = 0;
  for (int i = 0; i < 7; i += 1) {
    int c = (digit[i] == '1' ? 1 : 0);
    if (segments[which][i] == 0 && c == 1) return -1;
    if (segments[which][i] == c) continue;
    ret += 1;
  }
  return ret;
}
int main() {
  vector<vector<int>> segments = {
      {1, 1, 1, 0, 1, 1, 1}, {0, 0, 1, 0, 0, 1, 0}, {1, 0, 1, 1, 1, 0, 1},
      {1, 0, 1, 1, 0, 1, 1}, {0, 1, 1, 1, 0, 1, 0}, {1, 1, 0, 1, 0, 1, 1},
      {1, 1, 0, 1, 1, 1, 1}, {1, 0, 1, 0, 0, 1, 0}, {1, 1, 1, 1, 1, 1, 1},
      {1, 1, 1, 1, 0, 1, 1},
  };
  int n, k;
  cin >> n >> k;
  vector<vector<bool>> distances(n, vector<bool>(k + 1, false));
  vector<string> digits(n);
  for (int i = 0; i < n; i += 1) cin >> digits[i];
  for (int _num = 0; _num < 10; _num += 1) {
    int cdist = get_distance(segments, digits[n - 1], _num);
    if (cdist > k || cdist == -1) continue;
    distances[n - 1][cdist] = true;
  }
  for (int i = n - 2; i >= 0; i -= 1) {
    for (int _num = 0; _num < 10; _num += 1) {
      int cdist = get_distance(segments, digits[i], _num);
      if (cdist == -1) continue;
      for (int j = 0; j < k + 1; j += 1) {
        if (j + cdist > k) break;
        if (!distances[i + 1][j]) continue;
        distances[i][j + cdist] = true;
      }
    }
  }
  if (!distances[0][k]) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i += 1) {
    for (int _num = 9; _num >= 0; _num -= 1) {
      int cdist = get_distance(segments, digits[i], _num);
      if (cdist == -1 || cdist > k) continue;
      if (i != n - 1 && !distances[i + 1][k - cdist]) continue;
      if (i == n - 1 && cdist != k) continue;
      cout << _num;
      k -= cdist;
      break;
    }
  }
  cout << endl;
}
