#include <bits/stdc++.h>
using namespace std;
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const bool b) { return (b ? "true" : "false"); }
string to_string(const char* s) { return to_string((string)s); }
string to_string(const char c) {
  string s = "'";
  s += c;
  s += "'";
  return s;
}
template <class T, class U>
string to_string(const pair<T, U>& p) {
  string s = "(";
  s += to_string(p.first);
  s += ", ";
  s += to_string(p.second);
  s += ")";
  return s;
}
template <class T>
string to_string(const T& a) {
  bool first = true;
  string s = "{";
  for (const auto& x : a) {
    if (!first) {
      s += ", ";
    }
    first = false;
    s += to_string(x);
  }
  s += "}";
  return s;
}
void debug_out() { cerr << '\n'; }
template <class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
  cerr << ' ' << to_string(head);
  debug_out(tail...);
}
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 2e9;
const ll inf64 = 7e18l;
vector<int> numbers = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123};
int to_number(const string& s) {
  int cur = 0;
  for (char bit : s) {
    cur *= 2;
    if (bit == '1') {
      cur += 1;
    }
  }
  return cur;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    a[i] = to_number(s);
  }
  vector<vector<pair<int, int>>> dp(n + 1,
                                    vector<pair<int, int>>(k + 1, {-1, -1}));
  vector<vector<int>> par(n + 1, vector<int>(k + 1, -1));
  dp[n][0] = {1, 0};
  for (int i = n - 1; i >= 0; --i) {
    for (int kk = 0; kk <= k; ++kk) {
      for (int ind = 9; ind >= 0; --ind) {
        int num = numbers[ind];
        if ((a[i] & num) == a[i]) {
          int need = __builtin_popcount(a[i] ^ num);
          int old_k = kk - need;
          if (old_k < 0) {
            continue;
          }
          if (dp[i + 1][old_k].first == 1) {
            dp[i][kk].first = 1;
            dp[i][kk].second = ind;
            par[i][kk] = old_k;
            break;
          }
        }
      }
    }
  }
  if (dp[0][k].first == -1) {
    cout << -1 << '\n';
    return 0;
  }
  string answer;
  int cur = 0;
  int kk = k;
  while (cur < n) {
    answer += dp[cur][kk].second + '0';
    kk = par[cur][kk];
    ++cur;
  }
  cout << answer << '\n';
  return 0;
}
