#include <bits/stdc++.h>
using namespace std;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << ", " << p.second << "}";
  return os;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = (long long)1e9;
const long long INFLL = (long long)1e18 + 1;
const long long MOD = (long long)1e9 + 7;
const double PI = acos(-1.0);
string v[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
              "1101011", "1101111", "1010010", "1111111", "1111011"};
bool dp[2020][2020];
bool back[2020][2020];
int diff_(string &x, string &y) {
  int res = 0;
  for (int i = 0; i < int(x.size()); ++i) {
    if (x[i] == '1' && y[i] == '0') return -1;
    if (x[i] == '0' && y[i] == '1') res++;
  }
  return res;
}
void solve() {
  int N, K;
  cin >> N >> K;
  vec<string> a(N);
  for (int i = 0; i < int(N); ++i) cin >> a[i];
  for (int i = 0; i < int(N + 1); ++i)
    for (int j = 0; j < int(N + 1); ++j) {
      dp[i][j] = false;
      back[i][j] = false;
    }
  dp[0][0] = true;
  for (int i = 0; i < int(N); ++i) {
    for (int j = 0; j < int(K + 1); ++j) {
      if (!dp[i][j]) continue;
      for (int k = 0; k < int(10); ++k) {
        int cnt = diff_(a[i], v[k]);
        if (cnt == -1) continue;
        if (j + cnt > K) continue;
        dp[i + 1][j + cnt] = true;
      }
    }
  }
  if (!dp[N][K]) {
    cout << -1 << endl;
    return;
  }
  back[N][K] = true;
  for (int i = N; i >= 1; i--) {
    for (int j = 0; j <= K; ++j) {
      if (!back[i][j]) continue;
      for (auto &k : v) {
        int cnt = diff_(a[i - 1], k);
        if (cnt == -1) continue;
        if (j - cnt < 0) continue;
        if (!dp[i - 1][j - cnt]) continue;
        back[i - 1][j - cnt] = true;
      }
    }
  }
  string ans;
  int pre = 0;
  for (int i = 0; i < N; i++) {
    for (int k = 9; k >= 0; k--) {
      int cnt = diff_(a[i], v[k]);
      if (cnt == -1) continue;
      if (pre + cnt > K) continue;
      if (back[i + 1][pre + cnt]) {
        ans.push_back(char(k + '0'));
        pre = pre + cnt;
        break;
      }
    }
  }
  cout << ans << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  solve();
}
