#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 2007;
int dp[N][N];
pair<int, int> p[N][N];
string s[N];
int ok[N][N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<string> res;
  res.push_back("1110111");
  res.push_back("0010010");
  res.push_back("1011101");
  res.push_back("1011011");
  res.push_back("0111010");
  res.push_back("1101011");
  res.push_back("1101111");
  res.push_back("1010010");
  res.push_back("1111111");
  res.push_back("1111011");
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      dp[i][j] = -1;
      p[i][j] = {-1, -1};
    }
  }
  auto okk = [&](string a, string b) {
    int c = 0;
    for (int i = 0; i < 7; i++) {
      if (a[i] == '0' && b[i] == '1') {
        return -1;
      }
      if (a[i] == '1' && b[i] == '0') {
        c++;
      }
    }
    return c;
  };
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (int x = 0; x < 10; x++) {
    for (int i = 1; i <= n; i++) {
      ok[x][i] = okk(res[x], s[i]);
    }
  }
  dp[n + 1][0] = 0;
  for (int i = n; i >= 1; i--) {
    int cnt = 0;
    for (int j = 0; j < 7; j++) {
      cnt += (s[i][j] == '0');
    }
    for (int j = 0; j <= k; j++) {
      for (int x = 0; x < 10; x++) {
        int c = ok[x][i];
        if (c == -1 || dp[i + 1][j - c] == -1 || j - c < 0) {
          continue;
        }
        if (x > dp[i][j]) {
          dp[i][j] = x;
          p[i][j] = {i + 1, j - c};
        }
      }
    }
  }
  if (dp[1][k] == -1) {
    cout << -1 << '\n';
    return 0;
  }
  int x = 1, y = k;
  while (x <= n && y <= k) {
    cout << dp[x][y];
    int fx = x, fy = y;
    x = p[fx][fy].first;
    y = p[fx][fy].second;
  }
  cout << '\n';
  return 0;
}
