#include <bits/stdc++.h>
using namespace std;
vector<string> vs = {"1110111", "0010010", "1011101", "1011011", "0111010",
                     "1101011", "1101111", "1010010", "1111111", "1111011"};
int dis(string s, string t) {
  int ans = 0;
  for (int i = 0; i < 7; i++) {
    if (s[i] == t[i]) continue;
    if (s[i] == '0' && t[i] == '1')
      ans++;
    else
      return -1;
  }
  return ans;
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<string> mat = vector<string>(n);
  vector<int> dic(n);
  for (int i = 0; i < n; i++) cin >> mat[i];
  vector<vector<pair<int, int>>> dp = vector<vector<pair<int, int>>>(
      n, vector<pair<int, int>>(k + 1, {-1, -1}));
  vector<int> v = {0};
  for (int i = n - 1; i >= 0; i--) {
    vector<int> tv;
    for (int j = 9; j >= 0; j--) {
      int d = dis(mat[i], vs[j]);
      if (d != -1)
        for (int x : v) {
          if (x + d <= k && dp[i][x + d].first == -1) {
            dp[i][x + d] = {x, j};
            tv.push_back(x + d);
          }
        }
    }
    v = tv;
  }
  if (dp[0][k].first == -1) {
    cout << -1;
    return;
  }
  string ans(n, 0);
  int pre = k;
  for (int i = 0; i < n; i++) {
    ans[i] = '0' + dp[i][pre].second;
    pre = dp[i][pre].first;
  }
  cout << ans << endl;
}
int main() {
  int T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
