#include <bits/stdc++.h>
using namespace std;
long long n, k, dp[2005][2005];
string s[2005];
vector<long long> ans;
string dig[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                "1101011", "1101111", "1010010", "1111111", "1111011"};
long long make(string &s, string &num) {
  long long c = 0;
  for (long long i = 0; i < 8; i++)
    if (s[i] == '1' and num[i] == '0')
      return -1;
    else if (s[i] == '0' and num[i] == '1')
      c++;
  return c;
}
bool solve(long long i, long long rem) {
  if (i == n) return rem == 0;
  long long &res = dp[i][rem];
  if (res != -1) return res;
  long long fl = 0;
  for (long long d = 9; d >= 0; d--) {
    long long count = make(s[i], dig[d]);
    if (count != -1 and rem >= count and solve(i + 1, rem - count)) {
      ans.push_back(d);
      return res = 1;
    }
  }
  return res = 0;
}
void solve() {
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> s[i];
  memset(dp, -1, sizeof dp);
  if (!solve(0, k)) {
    cout << -1;
    return;
  }
  reverse((ans).begin(), (ans).end());
  for (auto i : ans) cout << i;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long TESTS = 1;
  while (TESTS--) {
    solve();
  }
  return 0;
}
