#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e18;
const int N = 2 * 1e3 + 10;
ll res;
ll a[N];
std::vector<string> v;
string s[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                "1101011", "1101111", "1010010", "1111111", "1111011"};
string sss;
ll dp[N][N];
bool go(ll idx, ll kk) {
  if (idx == v.size()) return dp[idx][kk] = !kk;
  if (dp[idx][kk] + 1) return dp[idx][kk];
  bool xx = 0;
  for (int i = 9; i >= 0; --i) {
    ll cost = 0, fl = 1;
    for (int j = 0; j < 7; ++j) {
      if (s[i][j] != v[idx][j]) cost++;
      if (v[idx][j] == '1') {
        if (s[i][j] == '0') fl = 0;
      }
    }
    if (kk - cost >= 0 && fl) xx = xx or go(idx + 1, kk - cost);
    if (xx) break;
  }
  return dp[idx][kk] = xx;
}
void goo(ll idx, ll kk) {
  if (idx == v.size()) return;
  for (int i = 9; i >= 0; --i) {
    ll cost = 0, fl = 1;
    for (int j = 0; j < 7; ++j) {
      if (s[i][j] != v[idx][j]) cost++;
      if (v[idx][j] == '1') {
        if (s[i][j] == '0') fl = 0;
      }
    }
    if (kk - cost >= 0 && fl) {
      if (dp[idx][kk] == dp[idx + 1][kk - cost] && dp[idx][kk] == 1) {
        sss.push_back(i + '0');
        goo(idx + 1, kk - cost);
        return;
      }
    }
  }
}
void solve() {
  ll n, k;
  cin >> n >> k;
  string ss;
  for (int i = 0; i < n; ++i) {
    cin >> ss;
    v.push_back(ss);
  }
  memset(dp, -1, sizeof dp);
  if (go(0, k)) {
    goo(0, k);
    cout << sss;
  } else {
    cout << -1;
  }
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  while (t--) {
    solve();
  }
}
