#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool umax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
long long POW(long long a, long long p, long long M) {
  if (!p) return 1LL;
  long long T = POW(a, p / 2, M);
  T = T * T % M;
  if (p & 1) T = T * (a % M) % M;
  return T;
}
long long SQRT(long long a) {
  long long b = (long long)sqrtl(((double)a) + 0.5);
  while (b * b < a) ++b;
  while (b * b > a) --b;
  return (b * b == a) ? b : -1;
}
const long long MOD = 1e9 + 7;
const int N = 130;
int ps[N][8];
int convertto[N][10];
vector<string> v = {"1110111", "0010010", "1011101", "1011011", "0111010",
                    "1101011", "1101111", "1010010", "1111111", "1111011"};
const int M = 2002;
int dp[M][M];
int solve(int ps, int k, int n, vector<int> &arr) {
  if (k < 0) return -2;
  if (ps == n) {
    if (k == 0) return 1;
    return -2;
  }
  if (dp[ps][k] != -1) return dp[ps][k];
  int ans = -2;
  for (int i = 0; i <= 9; i++) {
    int nd = convertto[arr[ps]][i];
    if (nd != -1 && solve(ps + 1, k - nd, n, arr) != -2)
      ans = convertto[arr[ps]][i];
  }
  return dp[ps][k] = ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  memset(convertto, -1, sizeof(convertto));
  for (int i = 0; i < v.size(); i++) reverse((v[i]).begin(), (v[i]).end());
  for (int i = 0; i <= 127; i++) {
    string s = std::bitset<7>(i).to_string();
    for (int j = 0; j < 8; j++) ps[i][j] = -1;
    for (int j = 0; j < v.size(); j++) {
      int cnt = 0;
      bool pos = 1;
      for (int k = 0; k < 7; k++) {
        if (s[k] == v[j][k]) continue;
        if (s[k] == '1')
          pos = 0;
        else
          cnt++;
      }
      if (pos) ps[i][cnt] = j;
      if (pos) {
        convertto[i][j] = cnt;
      }
    }
  }
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<string> vv(n);
  for (int i = 0; i < n; i++) cin >> vv[i];
  int mn = 0;
  vector<int> ech;
  vector<int> num;
  for (auto it : vv) {
    string gg = it;
    reverse((gg).begin(), (gg).end());
    int val = std::stoull(gg, 0, 2);
    num.push_back(val);
  }
  memset(dp, -1, sizeof(dp));
  int slv = solve(0, k, n, num);
  if (slv == -2) {
    cout << -1 << endl;
    return 0;
  }
  int st = 0;
  while (st != n) {
    int here = dp[st][k];
    cout << ps[num[st]][here];
    k -= here;
    st++;
  }
  cout << endl;
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}
