#include <bits/stdc++.h>
using namespace std;
const long double PI =
    3.141592653589793238462643383279502884197169399375105820974944;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long long maxn = 2e3 + 5;
vector<string> v({"1110111", "0010010", "1011101", "1011011", "0111010",
                  "1101011", "1101111", "1010010", "1111111", "1111011"});
string s[maxn];
long long n, k, dp[maxn][maxn], st[maxn][10];
void go(string t, long long x) {
  for (long long i = 0; i < 10; i++) {
    long long z = 0;
    for (long long j = 0; j < 8; j++) {
      if (s[x][j] == v[i][j])
        continue;
      else if (s[x][j] == '1') {
        z = -1;
        break;
      } else
        z++;
    }
    st[x][i] = z;
  }
}
void solve() {
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 0; i < n; i++) go(s[i], i);
  dp[n - 1][k] = 1;
  for (long long i = n - 1; i >= 1; --i) {
    for (long long x = 0; x <= k; x++) {
      if (dp[i][x]) {
        for (long long j = 0; j < 10; j++)
          if (st[i][j] != -1 && x - st[i][j] >= 0) dp[i - 1][x - st[i][j]] = 1;
      }
    }
  }
  string res = "";
  long long cur = 0;
  for (long long i = 0; i < n; i++) {
    long long ok = 0;
    for (long long j = 9; j >= 0; --j) {
      if (st[i][j] != -1 && dp[i][cur + st[i][j]]) {
        res += '0' + j;
        ok = 1;
        cur += st[i][j];
        break;
      }
    }
    if (!ok) {
      cout << -1;
      return;
    }
  }
  cout << res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tc = 1;
  while (tc--) {
    solve();
  }
  return 0;
}
