#include <bits/stdc++.h>
using namespace std;
int n, k, num[2001], dp[2001][2001], lts[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool pos[2001][10];
string db[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                 "1101011", "1101111", "1010010", "1111111", "1111011"},
       in;
bool ok(string x, int y) {
  for (int i = 0; i < 7; i++)
    if ((x[i] == '1') && (db[y][i] != '1')) return false;
  return true;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> in;
    for (int j = 0; j < 10; j++) pos[i][j] = ok(in, j);
    for (int j = 0; j < in.length(); j++)
      if (in[j] == '1') num[i]++;
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= k; j++) dp[i][j] = -1;
  dp[n][0] = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j <= k; j++) {
      for (int dig = 0; dig < 10; dig++) {
        int diff = lts[dig] - num[i];
        if ((diff <= j) && (dp[i + 1][j - diff] != -1) && (pos[i][dig]))
          dp[i][j] = dig;
      }
    }
  }
  if (dp[0][k] == -1)
    cout << -1 << endl;
  else {
    int cur = k;
    for (int i = 0; i < n; i++) {
      cout << dp[i][cur];
      int diff = lts[dp[i][cur]] - num[i];
      cur -= diff;
    }
    cout << endl;
  }
}
