#include <bits/stdc++.h>
using namespace std;
vector<string> dig = {"1110111", "0010010", "1011101", "1011011", "0111010",
                      "1101011", "1101111", "1010010", "1111111", "1111011"};
long long dist(string a, string b) {
  long long td = 0;
  for (long long i = 0; i < 7; ++i) {
    if (a[i] == '0' && b[i] == '1') ++td;
    if (a[i] == '1' && b[i] == '0') {
      td = 10;
      break;
    }
  }
  return td;
}
long long mind(string str) {
  long long d = 10;
  for (long long i = 0; i < 10; ++i) d = min(d, dist(str, dig[i]));
  return d;
}
long long maxd(string str) {
  long long d = 10;
  for (long long i = 0; i < 10; ++i)
    if (d == 10)
      d = dist(str, dig[i]);
    else if (dist(str, dig[i]) != 10)
      d = max(d, dist(str, dig[i]));
  return d;
}
vector<string> vec;
string ans;
vector<long long> min_dist, max_dist;
bool can(long long it, long long k) {
  if (k < 0) return 0;
  if (it == vec.size() && k == 0) return 1;
  if (it == vec.size() || min_dist[it] > k || k > max_dist[it]) return 0;
  bool ch = 0;
  for (long long i = 9; i >= 0; --i) {
    long long t = dist(vec[it], dig[i]);
    if (t != 10) {
      if (i != 0 || ans.size()) ans.push_back('0' + i);
      ch = can(it + 1, k - t);
      if (ch)
        return 1;
      else if (ans.size())
        ans.pop_back();
    }
  }
  return 0;
}
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  long long n, k;
  cin >> n >> k;
  min_dist.resize(n);
  max_dist.resize(n);
  vec.resize(n);
  for (long long i = 0; i < n; ++i) cin >> vec[i];
  min_dist.back() = mind(vec.back());
  max_dist.back() = maxd(vec.back());
  if (min_dist.back() == 10 || max_dist.back() == 10) {
    cout << -1;
    return 0;
  }
  for (long long i = n - 2; i >= 0; --i) {
    long long t1 = mind(vec[i]), t2 = maxd(vec[i]);
    min_dist[i] = min_dist[i + 1] + t1;
    max_dist[i] = max_dist[i + 1] + t2;
    if (t1 == 10 || t2 == 10) {
      cout << -1;
      return 0;
    }
  }
  if (can(0, k))
    if (ans.size())
      cout << ans;
    else
      cout << 0;
  else
    cout << -1;
  return 0;
}
