#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
string num[11] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                  "1101011", "1101111", "1010010", "1111111", "1111011"};
int cnt[maxn][10];
bool dp[maxn][maxn];
char ans[maxn];
string s[maxn];
int check(string a, string b) {
  int x = 0;
  for (int i = 0; i < 7; i++) {
    if (a[i] == '1' && b[i] == '0') return -1;
    if (a[i] == '0' && b[i] == '1') x++;
  }
  return x;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    for (int j = 0; j < 10; j++) {
      cnt[i][j] = check(s[i], num[j]);
    }
  }
  dp[n + 1][0] = true;
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j <= 9; j++) {
      if (cnt[i][j] == -1) {
        continue;
      }
      for (int u = cnt[i][j]; u <= k; u++) {
        dp[i][u] |= dp[i + 1][u - cnt[i][j]];
      }
    }
  }
  if (!dp[1][k]) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 9; j >= 0; j--) {
      if (cnt[i][j] == -1) {
        continue;
      }
      if (k >= cnt[i][j] && dp[i + 1][k - cnt[i][j]]) {
        ans[i] = j + '0';
        k -= cnt[i][j];
        break;
      }
    }
  }
  ans[n + 1] = '\0';
  cout << (ans + 1);
  return 0;
}
