#include <bits/stdc++.h>
using namespace std;
vector<string> digits = {"1110111", "0010010", "1011101", "1011011", "0111010",
                         "1101011", "1101111", "1010010", "1111111", "1111011"};
bitset<7> numbers[2000];
bitset<7> dig[10];
vector<int> ans;
bool dp[2001][2001];
int n, k;
int changes[2000][10];
void init() {
  for (int i = 0; i < 10; i++) dig[i] = bitset<7>(digits[i]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  init();
  cin >> n >> k;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    numbers[i] = bitset<7>(s);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      changes[i][j] = -1;
      if ((dig[j] | numbers[i]) == dig[j]) {
        changes[i][j] = (dig[j] ^ numbers[i]).count();
      }
    }
  }
  dp[n][0] = true;
  for (int i = n; i > 0; i--) {
    for (int j = 0; j <= k; j++) {
      if (dp[i][j]) {
        for (int d = 0; d <= 9; d++) {
          if (changes[i - 1][d] != -1 && (changes[i - 1][d]) + j <= k)
            dp[i - 1][j + changes[i - 1][d]] = true;
        }
      }
    }
  }
  if (!dp[0][k]) {
    cout << -1 << endl;
    return 0;
  }
  int k2 = k;
  for (int i = 0; i < n; i++) {
    for (int j = 9; j >= 0; j--) {
      if (changes[i][j] != -1 && k2 >= changes[i][j] &&
          dp[i + 1][k2 - changes[i][j]]) {
        cout << j;
        k2 -= changes[i][j];
        break;
      }
    }
  }
  return 0;
}
