#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> table(n), d = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123};
  for (int i = 0; i < n; ++i) {
    string tmp;
    cin >> tmp;
    reverse(tmp.begin(), tmp.end());
    for (int j = 0; j < 7; ++j) {
      if (tmp[j] == '1') {
        table[i] += (1 << j);
      }
    }
  }
  vector<vector<int>> dp(n + 1, vector<int>(k + 1, -1));
  vector<vector<int>> par(n + 1, vector<int>(k + 1, -1));
  dp[n][0] = 0;
  for (int i = n - 1; i >= 0; --i) {
    for (int j = 0; j <= k; ++j) {
      for (int k = 9; k >= 0; --k) {
        int cnt = __builtin_popcount(d[k] ^ table[i]);
        if (j >= cnt && (d[k] | table[i]) == d[k] && dp[i + 1][j - cnt] != -1) {
          dp[i][j] = k;
          par[i][j] = j - cnt;
          break;
        }
      }
    }
  }
  if (dp[0][k] == -1) {
    cout << -1 << '\n';
  } else {
    int i = 0, j = k;
    while (i < n && j >= 0) {
      cout << dp[i][j];
      j = par[i][j];
      ++i;
    }
    cout << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
