#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
const int N = 2e3 + 5, MOD = 1e9 + 7;
const long double EPS = 1e-9;
bool dp[N][N];
string num[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                "1101011", "1101111", "1010010", "1111111", "1111011"};
int dis(string a, string b) {
  int ans = 0;
  for (int i = 0; i < 7; i++) {
    if (a[i] != b[i]) {
      if (b[i] == '0')
        return -1;
      else
        ans++;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int i, j, n, k;
  cin >> n >> k;
  string s[n + 1];
  for (i = 1; i <= n; i++) cin >> s[i];
  dp[n + 1][0] = 1;
  for (i = n + 1; i > 1; i--) {
    for (j = 0; j <= k; j++) {
      if (dp[i][j]) {
        for (int cur = 0; cur <= 9; cur++) {
          int d = dis(s[i - 1], num[cur]);
          if (d >= 0 and j + d <= k) {
            dp[i - 1][j + d] = true;
          }
        }
      }
    }
  }
  if (!dp[1][k]) {
    cout << -1;
    exit(0);
  }
  string ans = "";
  int rem = k;
  for (i = 1; i <= n; i++) {
    int val = -1;
    for (int cur = 9; cur >= 0; cur--) {
      int d = dis(s[i], num[cur]);
      if (d >= 0 and dp[i + 1][rem - d]) {
        val = cur;
        rem -= d;
        ans += '0' + val;
        break;
      }
    }
    if (val == -1) {
      cout << -1;
      exit(0);
    }
  }
  cout << ans;
  return 0;
}
