#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  vector<string> ara = {"1110111", "0010010", "1011101", "1011011", "0111010",
                        "1101011", "1101111", "1010010", "1111111", "1111011"};
  vector<vector<long long int> > dist(n + 1);
  string s;
  for (long long int i = 1; i <= n; i++) {
    cin >> s;
    for (long long int p = 0; p < 10; p++) {
      long long int cnt = 0;
      for (long long int q = 0; q < 7; q++) {
        if (s[q] == '1' && ara[p][q] == '0') {
          cnt = -1;
          break;
        } else if (s[q] == '0' && ara[p][q] == '1')
          cnt++;
      }
      dist[i].push_back(cnt);
    }
  }
  int dp[n + 2][k + 1];
  memset(dp, 0, sizeof dp);
  dp[n + 1][0] = 1;
  for (long long int i = n; i > 0; i--) {
    for (long long int j = 0; j <= k; j++) {
      dp[i][j] = 0;
      for (long long int p = 0; p <= 9; p++) {
        long long int d = dist[i][p];
        if (d != -1 && j - d >= 0 && dp[i + 1][j - d] == 1) {
          dp[i][j] = 1;
          break;
        }
      }
    }
  }
  if (!dp[1][k])
    cout << -1 << endl;
  else {
    for (long long int i = 1; i <= n; i++) {
      for (long long int p = 9; p >= 0; p--) {
        long long int d = dist[i][p];
        if (d != -1 && k - d >= 0 && dp[i + 1][k - d] == 1) {
          k -= d;
          cout << p;
          break;
        }
      }
    }
  }
  return 0;
}
