#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
long long binpow(long long a, long long n) {
  long long i = 1;
  while (n > 0) {
    if (n & 1) i = (i * a) % 1000000007;
    a = (a * a) % 1000000007;
    n = n >> 1;
  }
  return i % 1000000007;
}
long long isprime(long long n) {
  if (n == 0 || n == 1) return n;
  if (n % 2 == 0) return (long long)2;
  if (n % 3 == 0)
    return (long long)3;
  else {
    for (long long i = 5; i * i <= n; i += 6) {
      if (n % i == 0) return i;
      if (n % (i + 2) == 0) return (i + 2);
    }
    return n;
  }
}
vector<string> digits = {"1110111", "0010010", "1011101", "1011011", "0111010",
                         "1101011", "1101111", "1010010", "1111111", "1111011"};
long long convertDigit(string& digit1, string& digit2) {
  long long cost = 0;
  for (long long i = 0; i < 7; ++i) {
    if (digit1[i] == '1' && digit2[i] == '0') return -1;
    cost += (digit1[i] != digit2[i]);
  }
  return cost;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long l, r, n, m, i, j, k, x, y, t;
  cin >> n >> k;
  vector<string> d(n + 1);
  for (i = 1; i <= n; ++i) {
    cin >> d[i];
  }
  vector<vector<long long> > dp(n + 2, vector<long long>(k + 1, -1));
  dp[n + 1][0] = 0;
  for (i = n; i >= 1; i--) {
    for (j = 0; j <= k; ++j) {
      for (long long cur = 9; cur >= 0; --cur) {
        long long cost = convertDigit(d[i], digits[cur]);
        if (cost == -1 | cost > j) continue;
        if (dp[i + 1][j - cost] != -1) {
          dp[i][j] = cur;
          break;
        }
      }
    }
  }
  if (dp[1][k] == -1) {
    cout << -1 << "\n";
    ;
    return 0;
  }
  for (i = 1; i <= n; ++i) {
    cout << dp[i][k];
    k -= convertDigit(d[i], digits[dp[i][k]]);
  }
}
