#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> digits;
vector<vector<bool>> dp;
vector<int> bin_digits;
bool can;
void In() {
  cin >> n >> k;
  digits.resize(n);
  string next;
  for (int i = 0; i < n; i++) {
    cin >> next;
    digits[i] = stoi(next, 0, 2);
  }
}
int GetDistance(int from, int result) {
  int count = 0;
  for (int bit = 0; bit <= 6; bit++) {
    int num = 1 << bit;
    int first = from & num;
    int second = result & num;
    if (first != second) {
      if (first == 0)
        count++;
      else
        return -1;
    }
  }
  return count;
}
bool Solve() {
  bin_digits.push_back(stoi("1110111", 0, 2));
  bin_digits.push_back(stoi("0010010", 0, 2));
  bin_digits.push_back(stoi("1011101", 0, 2));
  bin_digits.push_back(stoi("1011011", 0, 2));
  bin_digits.push_back(stoi("0111010", 0, 2));
  bin_digits.push_back(stoi("1101011", 0, 2));
  bin_digits.push_back(stoi("1101111", 0, 2));
  bin_digits.push_back(stoi("1010010", 0, 2));
  bin_digits.push_back(stoi("1111111", 0, 2));
  bin_digits.push_back(stoi("1111011", 0, 2));
  dp.resize(n + 1, vector<bool>(k + 1, false));
  dp[n][0] = true;
  for (int n_index = n - 1; n_index >= 0; n_index--)
    for (int i = 0; i <= k; i++)
      for (int j = 0; j <= 9; j++) {
        int next_distance = GetDistance(digits[n_index], bin_digits[j]);
        if (next_distance == -1) continue;
        if (i - next_distance < 0) continue;
        if (dp[n_index + 1][i - next_distance]) dp[n_index][i] = true;
      }
  if (!dp[0][k]) return false;
  return true;
}
void Out() {
  if (!can) {
    cout << -1 << endl;
    return;
  }
  for (int n_index = 0; n_index < n; n_index++) {
    int distance;
    int next_digit;
    for (int j = 0; j <= 9; j++) {
      int next_distance = GetDistance(digits[n_index], bin_digits[j]);
      if (next_distance == -1) continue;
      if (k - next_distance < 0) continue;
      if (dp[n_index + 1][k - next_distance]) {
        next_digit = j;
        distance = next_distance;
      }
    }
    k -= distance;
    cout << next_digit;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  In();
  can = Solve();
  Out();
}
