#include <bits/stdc++.h>
using namespace std;
bool compare(long long int a, long long int b) { return a > b; }
struct pair_hash {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2> &pair) const {
    return hash<T1>()(pair.first) ^ hash<T2>()(pair.second);
  }
};
bool dp[2005][2005];
void solve(long long int sum, long long int ind, vector<vector<int>> a,
           vector<long long int> &v, long long int n) {
  if (ind == n - 1) {
    for (long long int i = 9; i >= 0; i--) {
      if (a[ind][i] == sum) {
        v.push_back(i);
        return;
      }
    }
    return;
  }
  for (long long int i = 9; i >= 0; i--) {
    if (a[ind][i] != -1) {
      long long int x = a[ind][i];
      if (dp[ind + 1][sum - x] == true) {
        v.push_back(i);
        solve(sum - x, ind + 1, a, v, n);
        break;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  vector<string> num(10);
  num[0] = "1110111";
  num[1] = "0010010";
  num[2] = "1011101";
  num[3] = "1011011";
  num[4] = "0111010";
  num[5] = "1101011";
  num[6] = "1101111";
  num[7] = "1010010";
  num[8] = "1111111";
  num[9] = "1111011";
  long long int n, K;
  cin >> n >> K;
  vector<string> s(n);
  for (long long int i = 0; i < n; i++) cin >> s[i];
  vector<vector<int>> a(n);
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < 10; j++) {
      long long int fl = 1;
      long long int x = 0;
      for (long long int k = 0; k < 7; k++) {
        if (s[i][k] == '1' && num[j][k] == '0') {
          fl = 0;
          break;
        }
        if (s[i][k] == '0' && num[j][k] == '1') x++;
      }
      if (fl == 1)
        a[i].push_back(x);
      else
        a[i].push_back(-1);
    }
  }
  for (long long int i = 0; i < 2001; i++)
    for (long long int j = 0; j < 2001; j++) dp[i][j] = false;
  for (long long int j = 0; j < 10; j++) {
    if (a[n - 1][j] != -1) dp[n - 1][a[n - 1][j]] = true;
  }
  for (long long int i = n - 1; i >= 1; i--) {
    for (long long int k = 0; k < K + 1; k++) {
      if (dp[i][k] == 1) {
        for (long long int j = 0; j < 10; j++) {
          if (a[i - 1][j] != -1) dp[i - 1][k + a[i - 1][j]] = true;
        }
      }
    }
  }
  if (dp[0][K] == false) {
    cout << -1 << "\n";
    return 0;
  }
  vector<long long int> v;
  solve(K, 0, a, v, n);
  for (long long int i = 0; i < v.size(); i++) cout << v[i];
}
