#include <bits/stdc++.h>
using namespace std;
long long dp[2003][2003], n, k;
string num[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                  "1101011", "1101111", "1010010", "1111111", "1111011"};
string a[2003];
long long ans[2003];
long long fun(string &s, string &t) {
  long long c = 0;
  for (int i = 0; i < 7; ++i) {
    if (s[i] != t[i]) {
      if (s[i] == '1') return -1;
      c++;
    }
  }
  return c;
}
long long solve(long long idx, long long left) {
  if (idx == n) {
    return left == 0;
  }
  if (dp[idx][left] != -1) return dp[idx][left];
  long long f = 0;
  for (int i = 9; i >= 0; --i) {
    long long req = fun(a[idx], num[i]);
    if (req == -1) continue;
    if (req > left) continue;
    if (solve(idx + 1, left - req)) {
      f = 1;
      if (ans[idx] == -1) ans[idx] = i;
    }
  }
  return (dp[idx][left] = f);
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  memset(dp, -1, sizeof(dp));
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    ans[i] = -1;
    cin >> a[i];
  }
  long long pos = solve(0, k);
  if (pos) {
    for (int i = 0; i < n; ++i) {
      cout << ans[i];
    }
  } else
    cout << -1;
  return 0;
}
