#include <bits/stdc++.h>
using namespace std;
int n, k, dp[2005][2005];
string digits[2005],
    bits[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                "1101011", "1101111", "1010010", "1111111", "1111011"};
int kek(string s, int c) {
  int sm = 0;
  for (int i = 0; i < 7; i++) {
    if (s[i] == '1' && bits[c][i] == '0') return -1;
    sm += s[i] != bits[c][i];
  }
  return sm;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> digits[i];
  for (int j = 1; j <= n + 1; j++)
    for (int i = 0; i <= k; i++) dp[j][i] = -1;
  dp[n + 1][0] = 0;
  for (int i = n; i >= 1; i--)
    for (int j = 0; j <= k; j++) {
      for (int cif = 9; cif >= 0; cif--) {
        int cost = kek(digits[i], cif);
        if (cost == -1 || cost > j)
          continue;
        else if (dp[i + 1][j - cost] != -1) {
          dp[i][j] = cif;
          break;
        }
      }
    }
  if (dp[1][k] == -1) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    cout << dp[i][k];
    k -= kek(digits[i], dp[i][k]);
  }
}
