#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 2;
int cost[N][10], mem[N][N];
int n, k;
string digits[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                   "1101011", "1101111", "1010010", "1111111", "1111011"};
int solve(int idx, int rem) {
  if (idx == n) {
    return mem[idx][rem] = !rem;
  }
  int &ret = mem[idx][rem];
  if (~ret) return ret;
  ret = 0;
  for (int i = 9; i >= 0; --i) {
    if (rem >= cost[idx][i]) {
      ret |= solve(idx + 1, rem - cost[idx][i]);
    }
  }
  return ret;
}
void print(int idx, int rem) {
  if (idx == n) return;
  for (int i = 9; i >= 0; --i) {
    if (cost[idx][i] <= rem && mem[idx + 1][rem - cost[idx][i]]) {
      cout << i;
      print(idx + 1, rem - cost[idx][i]);
      return;
    }
  }
}
int main() {
  cin >> n >> k;
  string s;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    for (int j = 0; j <= 9; ++j) {
      for (int k = 0; k < 7; ++k) {
        if (s[k] == '0' && digits[j][k] == '1') cost[i][j]++;
        if (s[k] == '1' && digits[j][k] == '0') cost[i][j] = 100000;
      }
    }
  }
  memset(mem, -1, sizeof(mem));
  if (solve(0, k)) {
    print(0, k);
  } else {
    cout << -1;
  }
  return 0;
}
