#include <bits/stdc++.h>
const int maxN = 2010;
const int maxK = 2010;
std::string input[maxN];
bool DP[maxN][maxK];
int trans[maxN][10];
std::string digits[10] = {"1110111", "0010010", "1011101", "1011011",
                          "0111010", "1101011", "1101111", "1010010",
                          "1111111", "1111011"};
int calcTrans(std::string x, std::string y) {
  if (x.size() != y.size()) {
    std::exit(1);
  }
  int ret = 0;
  for (int i = 0; i < x.size(); ++i) {
    if (x[i] == '1' && y[i] == '0') {
      return -1;
    } else if (x[i] == '0' && y[i] == '1') {
      ++ret;
    }
  }
  return ret;
}
int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; ++i) {
    std::cin >> input[i];
    for (int j = 0; j < 10; ++j) {
      trans[i][j] = calcTrans(input[i], digits[j]);
    }
  }
  DP[N][0] = true;
  for (int i = N - 1; i >= 0; --i) {
    for (int j = 0; j <= K; ++j) {
      for (int k = 0; k < 10; ++k) {
        int t = trans[i][k];
        if (t != -1 && j - t >= 0 && DP[i + 1][j - t]) {
          DP[i][j] = true;
          break;
        }
      }
    }
  }
  std::string sol;
  for (int i = 0; i < N; ++i) {
    bool solExists = false;
    for (int j = 9; j >= 0; --j) {
      int transCost = trans[i][j];
      if (transCost == -1) {
        continue;
      }
      if (DP[i + 1][K - transCost]) {
        solExists = true;
        sol += '0' + j;
        K -= transCost;
        break;
      }
    }
    if (!solExists) {
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  std::cout << sol << std::endl;
  return 0;
}
