#include <bits/stdc++.h>
using namespace std;
int N, K, n[2005];
vector<int> ans;
void fail() {
  cout << "-1\n";
  exit(0);
}
int nms[10]{119, 18, 93, 91, 58, 107, 111, 82, 127, 123};
bool vis[2005][2005];
bool memo[2005][2005];
int bintodec(string s) {
  int ans = 0;
  for (auto x : s) {
    ans *= 2;
    if (x == '1') ans++;
  }
  return ans;
}
bool dp(int x, int k) {
  if (x > N) return memo[x][k] = k == 0;
  if (vis[x][k]) return memo[x][k];
  bool ans = false;
  for (int i = 9; i >= 0; i--)
    if ((n[x] & nms[i]) == n[x]) {
      int dif = __builtin_popcount(nms[i]) - __builtin_popcount(n[x]);
      if (dif > k) continue;
      ans |= dp(x + 1, k - dif);
    }
  vis[x][k] = 1;
  return memo[x][k] = ans;
}
void solve(int x, int k) {
  if (x > N) return;
  for (int i = 9; i >= 0; i--)
    if ((n[x] & nms[i]) == n[x]) {
      int dif = __builtin_popcount(nms[i]) - __builtin_popcount(n[x]);
      if (dif > k or !memo[x + 1][k - dif]) continue;
      cout << i;
      solve(x + 1, k - dif);
      return;
    }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> N >> K;
  for (int i = 1; i <= N; i++) {
    string s;
    cin >> s;
    n[i] = bintodec(s);
  }
  if (!dp(1, K)) fail();
  solve(1, K);
  return 0;
}
