#include <bits/stdc++.h>
using namespace std;
vector<string> digits = {"1110111", "0010010", "1011101", "1011011", "0111010",
                         "1101011", "1101111", "1010010", "1111111", "1111011"};
bitset<7> numbers[2000];
bitset<7> dig[10];
vector<int> ans;
bool dp[2000][2000];
int n, k;
bool solve(int pos, int rem) {
  if (rem < 0) return false;
  if (pos == n) return rem == 0;
  if (!dp[pos][rem]) return false;
  for (int i = 9; i >= 0; i--) {
    if ((dig[i] | numbers[pos]) == dig[i]) {
      int d = (dig[i] ^ numbers[pos]).count();
      ans.push_back(i);
      if (solve(pos + 1, rem - d)) {
        return true;
      }
      ans.pop_back();
    }
  }
  return dp[pos][rem] = false;
}
void init() {
  for (int i = 0; i < 10; i++) dig[i] = bitset<7>(digits[i]);
  memset(dp, true, sizeof(dp));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  init();
  cin >> n >> k;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    numbers[i] = bitset<7>(s);
  }
  bool valid = solve(0, k);
  if (valid) {
    for (auto v : ans) cout << v;
  } else
    cout << -1;
  return 0;
}
