#include <bits/stdc++.h>
using namespace std;
int n, k;
bool vis[2100][2100];
int ans[3000], a[3000];
int defa[] = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123};
void dfs(int i, int x) {
  if (x > k || vis[i][x]) return;
  vis[i][x] = 1;
  if (i == n) {
    if (x == k) {
      for (int j = 0; j < n; j++) cout << ans[j];
      exit(0);
    }
    return;
  }
  for (int j = 9; j >= 0; j--) {
    ans[i] = j;
    if ((defa[j] & a[i]) == a[i])
      dfs(i + 1, x + __builtin_popcount(defa[j] ^ a[i]));
  }
}
int main() {
  cin >> n >> k;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    a[i] = stoi(s, 0, 2);
  }
  dfs(0, 0);
  cout << -1;
}
