#include <bits/stdc++.h>
using namespace std;
char num[10][8] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                   "1101011", "1101111", "1010010", "1111111", "1111011"};
long long n, k, flag = 0;
long long al[2005][2005] = {0};
char a[2005][8];
long long ans[2005];
void dfs(long long x) {
  if (x == n) {
    if (k == 0) {
      for (int i = 0; i < n; i++) cout << ans[i];
      cout << endl;
      flag = 1;
    }
    return;
  }
  for (int i = 9; i >= 0; i--) {
    long long b = 1, t = 0;
    for (int j = 0; j < 7; j++) {
      if (a[x][j] == '1' && num[i][j] == '0') {
        b = 0;
        break;
      } else if (a[x][j] == '0' && num[i][j] == '1')
        t++;
    }
    if (b != 0 && k >= t && al[x][k - t] == 0) {
      al[x][k - t] = 1;
      ans[x] = i;
      k -= t;
      dfs(x + 1);
      if (flag == 1) return;
      k += t;
    }
  }
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  dfs(0);
  if (flag == 0) cout << "-1" << endl;
  return 0;
}
