#include <bits/stdc++.h>
using namespace std;
string s[2005];
string v[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
              "1101011", "1101111", "1010010", "1111111", "1111011"};
int n, m, k, l, r, x, y;
pair<int, int> ans[2005][2005];
inline pair<bool, int> dis(string a, string b) {
  int z = 0;
  for (int i = 0; i < 7; ++i) {
    if (a[i] == '1' && b[i] == '0') return {false, -1};
    if (a[i] == '0' && b[i] == '1') ++z;
  }
  return {true, z};
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  for (int i = 0; i < 2005; ++i) {
    for (int j = 0; j < 2005; ++j) {
      ans[i][j].first = -1;
    }
  }
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = n - 1; i >= 0; --i) {
    pair<bool, int> d[10];
    for (int digit = 0; digit < 10; ++digit) {
      d[digit] = dis(s[i], v[digit]);
    }
    for (int j = 0; j <= k; ++j) {
      for (int digit = 9; digit >= 0; --digit) {
        auto z = d[digit];
        if (z.first &&
            ((i == n - 1 && j - z.second == 0) ||
             (j - z.second >= 0 && ans[i + 1][j - z.second].first != -1))) {
          ans[i][j] = {digit, j - z.second};
          break;
        }
      }
    }
  }
  if (ans[0][k].first == -1) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    cout << ans[i][k].first;
    k = ans[i][k].second;
  }
}
