#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
string s[N], p[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                      "1101011", "1101111", "1010010", "1111111", "1111011"};
int n, t[N][10], cache[N][10][N];
int check(int i, int digit) {
  int cnt = 0;
  for (int k = 0; k < 7; k++) {
    if (p[digit][k] != s[i][k] and s[i][k] == '1') {
      return 1e5;
    }
    if (p[digit][k] != s[i][k] and s[i][k] == '0') {
      cnt++;
    }
  }
  return cnt;
}
int dp(int ind, int digit, int have) {
  if (ind == n) {
    return (have == 0);
  }
  int &ans = cache[ind][digit][have];
  if (ans != -1) {
    return ans;
  }
  ans = 0;
  for (int i = 9; i >= 0; i--) {
    int need = t[ind + 1][i];
    if (have >= need) {
      ans |= dp(ind + 1, i, have - need);
    }
  }
  return ans;
}
void path(int ind, int digit, int have) {
  cout << digit;
  if (ind == n) {
    return;
  }
  for (int i = 9; i >= 0; i--) {
    int need = t[ind + 1][i];
    if (have >= need and dp(ind + 1, i, have - need)) {
      return path(ind + 1, i, have - need);
    }
  }
}
void solve() {
  int k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    for (int digit = 0; digit < 10; digit++) {
      int need = check(i, digit);
      t[i][digit] = need;
    }
  }
  memset(cache, -1, sizeof(cache));
  for (int i = 9; i >= 0; i--) {
    if (k - t[1][i] >= 0 and dp(1, i, k - t[1][i])) {
      path(1, i, k - t[1][i]);
      return;
    }
  }
  cout << "-1\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int tc = 1;
  while (tc--) {
    solve();
  }
  return 0;
}
