#include <bits/stdc++.h>
using namespace std;
int poss(char *s1, char *s2, int l, int flag2) {
  int flag = 1, count = 0;
  for (int i = 0; i < 7; ++i) {
    if (s2[i] == '0' && s1[i] == '1')
      flag = 0;
    else {
      if (s2[i] == '1' && s1[i] == '0') count++;
    }
  }
  if (flag2 == 1)
    if (count != l)
      flag = 0;
    else {
      if (count > l) flag = 0;
    }
  if (flag) return count;
  return -1;
}
int main() {
  char *v1[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                  "1101011", "1101111", "1010010", "1111111", "1111011"};
  int n, k;
  cin >> n >> k;
  char *v2[n];
  for (int i = 0; i < n; ++i) {
    v2[i] = (char *)malloc(sizeof(char) * 8);
    scanf("%s", v2[i]);
  }
  int b[n][k + 1][10];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < k + 1; ++j) {
      for (int l = 0; l < 10; ++l) b[i][j][l] = 0;
    }
  }
  int bi[n][k + 1];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < k + 1; ++j) bi[i][j] = -1;
  }
  for (int j = 0; j < k + 1; ++j) {
    for (int r = 0; r < 10; ++r) {
      b[0][j][r] = poss(v2[n - 1], v1[r], j, 1);
      if (b[0][j][r] != -1) bi[0][j] = r;
    }
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < k + 1; ++j) {
      for (int r = 0; r < 10; ++r) {
        int t = poss(v2[n - 1 - i], v1[r], j, 0);
        if (t != -1 && t <= j) {
          if (bi[i - 1][j - t] != -1) {
            b[i][j][r] = t;
            bi[i][j] = r;
          }
        }
      }
    }
  }
  int st = n - 1, c = k;
  vector<int> v3;
  while (st > -1) {
    v3.push_back(bi[st][c]);
    c = c - b[st][c][bi[st][c]];
    st--;
  }
  if (v3[0] == -1)
    cout << "-1\n";
  else {
    for (int i = 0; i < n; ++i) cout << v3[i];
  }
}
