#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
long long bigmod(long long a, long long b, long long c) {
  if (b == 0) return 1 % c;
  long long x = bigmod(a, b / 2, c);
  x = (x * x) % c;
  if (b % 2 == 1) x = (x * a) % c;
  return x;
}
long long mod_inverse(long long a, long long mod) {
  return bigmod(a, mod - 2, mod);
}
string dg[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
               "1101011", "1101111", "1010010", "1111111", "1111011"};
string s[2005];
int n, k;
int dp[2002][2002][11];
int pcl[2005][12];
long long dpcall(int id, int r, int d) {
  int &ret = dp[id][r][d];
  if (id == n) {
    if (r) return ret = 0;
    return ret = 1;
  }
  if (~ret) return ret;
  ret = 0;
  for (int j = 0; j <= 9; j++) {
    int need = pcl[id][j];
    if (need <= r) {
      int now = dpcall(id + 1, r - need, j);
      ret = ret || now;
    }
  }
  return ret;
}
void dfs(int id, int r, int d) {
  if (id == n) {
    return;
  }
  for (int j = 9; j >= 0; j--) {
    int need = 0;
    for (int i = 0; i < (7); i++) {
      if (s[id][i] == '1' && dg[j][i] == '0') {
        need = 20000;
        break;
      } else if (s[id][i] == '0' && dg[j][i] == '1') {
        need++;
      }
    }
    if (need <= r && dp[id + 1][r - need][j] == 1) {
      cout << j;
      dfs(id + 1, r - need, j);
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int id = 0; id < n; id++) {
    cin >> s[id];
    for (int j = 0; j < (10); j++) {
      int need = 0;
      for (int i = 0; i < (7); i++) {
        if (s[id][i] == '1' && dg[j][i] == '0') {
          need = 20000;
          break;
        } else if (s[id][i] == '0' && dg[j][i] == '1') {
          need++;
        }
      }
      pcl[id][j] = need;
    }
  }
  memset((dp), -1, sizeof(dp));
  int ret = dpcall(0, k, 10);
  if (!ret) {
    cout << -1 << endl;
    return 0;
  }
  dfs(0, k, 10);
  cout << endl;
  return 0;
}
