#include <bits/stdc++.h>
using namespace std;
char str[20];
int n;
int digit[] = {
    0b1110111, 0b0010010, 0b1011101, 0b1011011, 0b0111010,
    0b1101011, 0b1101111, 0b1010010, 0b1111111, 0b1111011,
};
int indx[200];
int ar[2009];
int getNumber(char str[]) {
  int x = 0;
  for (int i = 0; i < 7; i++) {
    if (str[i] == '1') {
      x = x | (1 << (6 - i));
    }
  }
  return x;
}
inline bool isSub(int x, int y) { return (x | y) == x; }
inline int changes(int x, int y) { return __builtin_popcount(x ^ y); }
int dp[2009][2009];
int res[2009][2009];
int func(int ind, int k) {
  if (k < 0) {
    return 0;
  }
  if (ind >= n) {
    return (k == 0);
  }
  int &ret = dp[ind][k];
  if (~ret) return ret;
  ret = 0;
  int d = ar[ind];
  for (int i = 9; i >= 0; i--) {
    if (isSub(digit[i], d) && func(ind + 1, k - changes(d, digit[i]))) {
      ret = 1;
      res[ind][k] = i;
      return ret;
    }
  }
  res[ind][k] = -1;
  return ret;
}
void pathPrint(int ind, int k) {
  if (ind >= n) {
    puts("");
    return;
  }
  if (k < 0) {
    puts("WTF!");
    assert(false);
    return;
  }
  printf("%d", res[ind][k]);
  pathPrint(ind + 1, k - changes(ar[ind], digit[res[ind][k]]));
}
int main() {
  int k, i;
  for (i = 0; i < 10; i++) {
    indx[digit[i]] = i;
  }
  scanf("%d %d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%s", str);
    ar[i] = getNumber(str);
  }
  memset(dp, -1, sizeof(dp));
  if (!func(0, k)) {
    puts("-1");
  } else {
    pathPrint(0, k);
  }
  return 0;
}
