#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
using namespace std;
int n, k;
int val[10] = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123};
vector<int> a;
inline int cnt(int mask) {
  int ans = 0;
  for (int i = 0; i < 8; i++) {
    if (mask >> i & 1) {
      ans++;
    }
  }
  return ans;
}
int to_val(string& s) {
  reverse((s).begin(), (s).end());
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      ans += (1 << i);
    }
  }
  return ans;
}
void solve() {
  vector<vector<int> > dp(n + 1, vector<int>(k + 1, -1));
  vector<vector<int> > prev(n + 1, vector<int>(k + 1, -1));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= k; j++) {
      if (dp[i][j] == -1) {
        continue;
      }
      for (int z = 0; z < 10; z++) {
        if ((a[n - 1 - i] & val[z]) == a[n - 1 - i]) {
          int need = a[n - 1 - i] ^ val[z];
          int add = cnt(need);
          if (j + add > k) {
            continue;
          }
          if (z > dp[i + 1][j + add]) {
            dp[i + 1][j + add] = z;
            prev[i + 1][j + add] = j;
          }
        }
      }
    }
  }
  if (dp[n][k] == -1) {
    cout << "-1\n";
  } else {
    int x = n;
    int y = k;
    while (prev[x][y] != -1) {
      assert(x >= 0 && y >= 0);
      cout << dp[x][y];
      assert(prev[x][y] != -1);
      y = prev[x][y];
      x--;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    a[i] = to_val(s);
  }
  solve();
  return 0;
}
