#include <bits/stdc++.h>
using namespace std;
string snum[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                   "1101011", "1101111", "1010010", "1111111", "1111011"};
int vnum[10];
const int N = 2005;
int n;
int dp[N][N];
int val[N];
int rec(int idx, int lft) {
  if (idx == n) {
    if (lft == 0) return 1;
    return 0;
  }
  if (lft < 0) return 0;
  if (dp[idx][lft] != -1) return dp[idx][lft];
  int res = 0;
  int cur_num = val[idx];
  for (int i = 9; i >= 0; --i) {
    if ((vnum[i] | cur_num) != vnum[i]) continue;
    int diff = __builtin_popcount(vnum[i] ^ cur_num);
    res = max(res, rec(idx + 1, lft - diff));
  }
  return dp[idx][lft] = res;
}
void bt(int idx, int lft) {
  if (idx == n) return;
  int cur_num = val[idx];
  for (int i = 9; i >= 0; --i) {
    if ((vnum[i] | cur_num) != vnum[i]) continue;
    int diff = __builtin_popcount(vnum[i] ^ cur_num);
    if (rec(idx + 1, lft - diff)) {
      cout << i;
      bt(idx + 1, lft - diff);
      break;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < 10; ++i) {
    vnum[i] = 0;
    for (int j = 0; j < snum[i].length(); ++j) {
      vnum[i] *= 2;
      vnum[i] += snum[i][j] - '0';
    }
  }
  int k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < s.length(); ++j) {
      val[i] *= 2;
      val[i] += s[j] - '0';
    }
  }
  memset(dp, -1, sizeof dp);
  if (!rec(0, k)) {
    cout << -1 << endl;
    return 0;
  }
  bt(0, k);
  cout << endl;
}
