#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int N = 1e6 + 6, mod = 998244353, M = 1e7 + 7;
const long long MAX = 5e18;
int n, k, dp[2001][2001], dif[2001][10];
string d[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                "1101011", "1101111", "1010010", "1111111", "1111011"};
string s[2001];
int clcDif(string s, string t) {
  int ret = 0;
  for (int i = 0; i < 7; i++) {
    if (s[i] == '1' && t[i] == '0') return -1;
    ret += (s[i] != t[i]);
  }
  return ret;
}
bool canSlv(int i = 0, int r = k) {
  if (i == n) return r == 0;
  int& ret = dp[i][r];
  if (ret != -1) return ret;
  ret = 0;
  for (int j = 0; j < 10; j++) {
    int t = dif[i][j];
    if (t != -1 && t <= r && canSlv(i + 1, r - t)) ret = 1;
  }
  return ret;
}
void slv(int i = 0, int r = k) {
  if (i == n) return;
  for (int j = 9; j >= 0; j--) {
    int t = dif[i][j];
    if (t != -1 && canSlv(i + 1, r - t)) {
      cout << j;
      slv(i + 1, r - t);
      return;
    }
  }
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < 10; j++) dif[i][j] = clcDif(s[i], d[j]);
  }
  if (!canSlv())
    puts("-1");
  else
    slv();
  return 0;
}
