#include <bits/stdc++.h>
using namespace std;
template <class Cont>
int sz(const Cont& cont) {
  return cont.size();
}
vector<string> digits = {"1110111", "0010010", "1011101", "1011011", "0111010",
                         "1101011", "1101111", "1010010", "1111111", "1111011"};
int Dist(string& dig, int num) {
  string& a = digits[num];
  int ans = 0;
  for (int i = 0; i < 7; ++i) {
    if (dig[i] == '0' && a[i] == '1') ++ans;
    if (dig[i] == '1' && a[i] == '0') return -1;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<string> strs(n);
  for (auto& str : strs) cin >> str;
  vector<vector<bool>> possible(n + 1, vector<bool>(k + 1));
  possible[n][0] = true;
  for (int j = n - 1; j >= 0; --j) {
    vector<int> dists(10);
    for (int m = 0; m < 10; ++m) {
      dists[m] = Dist(strs[j], m);
    }
    for (int cnt = 0; cnt < k + 1; ++cnt) {
      for (int m = 0; m < 10; ++m) {
        if (dists[m] != -1) {
          int left = cnt - dists[m];
          if (left >= 0 && possible[j + 1][left]) {
            possible[j][cnt] = true;
            break;
          }
        }
      }
    }
  }
  if (!possible[0][k])
    cout << -1;
  else {
    string ans;
    for (int j = 0; j < n; ++j) {
      for (int num = 9; num >= 0; --num) {
        int dis = Dist(strs[j], num);
        if (dis != -1) {
          int left = k - dis;
          if (left >= 0 && possible[j + 1][left]) {
            k -= dis;
            ans.push_back('0' + num);
            break;
          }
        }
      }
    }
    cout << ans;
  }
  return 0;
}
