#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int mn = 2500;
int n, k, u[mn][mn], pr[mn][mn], d[mn][mn];
string second, ans;
vector<int> a, b;
vector<string> first = {"1110111", "0010010", "1011101", "1011011", "0111010",
                        "1101011", "1101111", "1010010", "1111111", "1111011"};
signed main() {
  iostream::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int t = 0; t < n; t++) {
    cin >> second;
    vector<int> cnt(10, 0);
    for (int x = 0; x <= 9; x++) {
      for (int i = 0; i < 7; i++) {
        if (second[i] == '1' && first[x][i] == '1') continue;
        if (second[i] == '1' && first[x][i] == '0') cnt[x] = -1e6;
        if (second[i] == '0' && first[x][i] == '1') cnt[x]++;
      }
    }
    if (t == 0) {
      for (int x = 9; x >= 0; x--)
        if (cnt[x] >= 0 && cnt[x] <= k && u[0][cnt[x]] == 0) {
          u[0][cnt[x]] = 1;
          d[0][cnt[x]] = x;
          a.push_back(cnt[x]);
        }
      continue;
    }
    b.clear();
    for (int c : a) {
      for (int x = 9; x >= 0; x--)
        if (cnt[x] >= 0 && c + cnt[x] <= k && u[t][c + cnt[x]] == 0) {
          u[t][c + cnt[x]] = 1;
          d[t][c + cnt[x]] = x;
          pr[t][c + cnt[x]] = c;
          b.push_back(c + cnt[x]);
        }
    }
    a = b;
  }
  if (u[n - 1][k] == 0) {
    cout << "-1";
    exit(0);
  }
  for (int t = n - 1; t >= 0; t--) {
    ans.push_back('0' + d[t][k]);
    k = pr[t][k];
  }
  reverse(ans.begin(), ans.end());
  cout << ans;
  return 0;
}
