#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10;
string s[2003];
string name[10];
long long dp[2005][12];
long long via[2005][2005];
long long ans[2005], flag, n, k;
map<string, long long> mp;
void dfs(long long pos, long long sum) {
  if (flag == 1 || sum < 0) return;
  if (pos >= n) {
    if (sum == 0) {
      flag = 1;
      for (long long i = 0; i < n; i++) cout << ans[i];
      cout << endl;
    } else
      return;
  }
  if (via[pos][sum] == -1) return;
  for (long long i = 9; i >= 0; i--) {
    if (dp[pos][i] == -1) continue;
    ans[pos] = i;
    dfs(pos + 1, sum - dp[pos][i]);
  }
  if (flag == 0) via[pos][sum] = -1;
}
signed main() {
  name[0] = "1110111", name[1] = "0010010", name[2] = "1011101",
  name[3] = "1011011", name[4] = "0111010", name[5] = "1101011",
  name[6] = "1101111", name[7] = "1010010", name[8] = "1111111",
  name[9] = "1111011";
  cin >> n >> k;
  for (long long i = 0; i < n; i++) ans[i] = 0;
  for (long long i = 0; i < n; i++) {
    cin >> s[i];
    for (long long num = 0; num <= 9; num++) {
      long long cnt = 0, isp = 1;
      for (long long j = 0; j < 7; j++) {
        if (name[num][j] == s[i][j]) {
        } else if (name[num][j] == '1' && s[i][j] == '0') {
          cnt++;
        } else {
          isp = 0;
          break;
        }
      }
      if (isp == 0)
        dp[i][num] = -1;
      else
        dp[i][num] = cnt;
    }
  }
  flag = 0;
  dfs(0, k);
  if (flag == 0) cout << "-1" << endl;
  return 0;
}
