#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int n, k;
string ss[2050];
int ans[2050];
bool vis[2050][2050];
bool suc = 0;
string s[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                "1101011", "1101111", "1010010", "1111111", "1111011"};
void dfs(int now, int left) {
  if (now == n && left == 0) {
    suc = 1;
    return;
  }
  if (now == n) {
    return;
  }
  if (vis[now][left]) {
    return;
  } else {
    vis[now][left] = 1;
  }
  for (int i = 9; i >= 0; i--) {
    bool flag = 0;
    int cnt = 0;
    for (int j = 0; j < 9; j++) {
      if (ss[now][j] > s[i][j]) {
        flag = 1;
        break;
      } else if (ss[now][j] < s[i][j]) {
        cnt++;
      }
    }
    if (!flag) {
      if (left >= cnt) {
        ans[now] = i;
        dfs(now + 1, left - cnt);
      }
    }
    if (suc) {
      return;
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> ss[i];
  }
  dfs(0, k);
  if (suc == 0) {
    cout << -1 << '\n';
  } else {
    for (int i = 0; i < n; i++) {
      cout << ans[i];
    }
    cout << '\n';
  }
  return 0;
}
