#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  while (true) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    long long p = b % a, q = a;
    a = p;
    b = q;
  }
}
long long powerMod(long long x, long long y) {
  long long res = 1;
  x %= 998244353;
  while (y > 0) {
    if (y & 1) res = (res * x) % 998244353;
    y = y >> 1;
    x = (x * x) % 998244353;
  }
  return res % 998244353;
}
string binary(long long s) {
  string res = "";
  while (s != 0) {
    res += (char)('0' + s % 2);
    s /= 2;
  }
  reverse(res.begin(), res.end());
  return res;
}
vector<string> a, b = {"1110111", "0010010", "1011101", "1011011", "0111010",
                       "1101011", "1101111", "1010010", "1111111", "1111011"};
vector<vector<int> > dp;
vector<vector<pair<int, int> > > cc;
int n;
string ans;
void prec() {
  for (int idx = 0; idx < n; idx++) {
    vector<pair<int, int> > c;
    for (int i = 0; i < 10; i++) {
      int p = 0, j;
      for (j = 0; j < 7; j++) {
        if (a[idx][j] == '1' && b[i][j] == '0') {
          break;
        }
        if (a[idx][j] == '0' && b[i][j] == '1') {
          p++;
        }
      }
      if (j == 7) {
        c.push_back({i, p});
      }
    }
    cc.push_back(c);
  }
}
int rec(int idx, int k) {
  if (k < 0) {
    return 0;
  } else if (idx == n) {
    if (k == 0) {
      return dp[idx][k] = 1;
    } else
      return dp[idx][k] = 0;
  }
  if (dp[idx][k] > -1) return dp[idx][k];
  vector<pair<int, int> > c = cc[idx];
  for (auto i : c) {
    dp[idx][k] = max(dp[idx][k], rec(idx + 1, k - i.second));
  }
  return dp[idx][k];
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int k, i, j, l, m, p;
  cin >> n >> k;
  a.resize(n);
  dp.resize(n + 1, vector<int>(k + 1, -1));
  for (auto &i : a) {
    cin >> i;
  }
  prec();
  m = rec(0, k);
  if (m == 0) {
    cout << -1 << "\n";
    return 0;
  }
  ans = "";
  j = k;
  for (i = 0; i < n; i++) {
    int maxn = -1;
    vector<pair<int, int> > c = cc[i];
    for (auto ii : c) {
      if (j - ii.second < 0) continue;
      if (dp[i + 1][j - ii.second] == 1) {
        maxn = max(maxn, ii.first);
      }
    }
    int flag = 0;
    for (auto ii : c) {
      if (j - ii.second < 0) continue;
      if (dp[i + 1][j - ii.second] == 1) {
        if (maxn == ii.first) {
          j = j - ii.second;
          flag = 1;
          break;
        }
      }
    }
    ans += (char)(maxn + 48);
  }
  cout << ans << "\n";
  return 0;
}
