#include <bits/stdc++.h>
using namespace std;
struct Object {
  int digit;
  int cost;
};
int GetCost(const string &str, int digit) {
  static const vector<string> kDigits = {
      "1110111", "0010010", "1011101", "1011011", "0111010",
      "1101011", "1101111", "1010010", "1111111", "1111011"};
  auto cost = 0;
  for (size_t i = 0; i < str.size(); i += 1) {
    if (kDigits[digit][i] == '0' && str[i] == '1') {
      return -1;
    }
    cost += (kDigits[digit][i] != str[i] ? 1 : 0);
  }
  return cost;
}
vector<Object> GetObjects(const string &str) {
  vector<Object> objects;
  for (int i = 9; i >= 0; i -= 1) {
    auto cost = GetCost(str, i);
    if (cost >= 0) {
      objects.push_back((Object){.digit = i, .cost = cost});
    }
  }
  return objects;
}
string ExtractNumber(const vector<string> &digits,
                     const vector<vector<int>> &max_digits) {
  int moves = max_digits[0].size() - 1;
  if (max_digits[0][moves] < 0) {
    return "-1";
  }
  string res = "";
  for (size_t i = 0; i < max_digits.size(); i += 1) {
    auto chosen = max_digits[i][moves];
    res.push_back('0' + chosen);
    moves -= GetCost(digits[i], chosen);
  }
  return res;
}
string Solve(const vector<string> &digits, int moves) {
  vector<vector<int>> max_digit(digits.size(), vector<int>(moves + 1, -1));
  for (const auto &obj : GetObjects(digits.back())) {
    if (obj.cost <= moves && max_digit.back()[obj.cost] == -1) {
      max_digit.back()[obj.cost] = obj.digit;
    }
  }
  for (int i = digits.size() - 2; i >= 0; i -= 1) {
    auto objects = GetObjects(digits[i]);
    for (int j = 0; j <= moves; j += 1) {
      for (const auto &obj : objects) {
        if (obj.cost <= j && max_digit[i + 1][j - obj.cost] >= 0) {
          max_digit[i][j] = obj.digit;
          break;
        }
      }
    }
  }
  return ExtractNumber(digits, max_digit);
}
int main() {
  int n, moves;
  cin >> n >> moves;
  cin.get();
  vector<string> digits(n);
  for (auto &d : digits) {
    getline(cin, d);
  }
  auto res = Solve(digits, moves);
  cout << res << "\n";
  return 0;
}
