#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
bool dp[maxn][maxn];
char s[maxn][20];
int val[maxn][10];
char eg[][20] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                 "1101011", "1101111", "1010010", "1111111", "1111011"};
int n, k;
void init() {
  memset(val, -1, sizeof(val));
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 10; j++) {
      int num = 0;
      int flag = 1;
      for (int o = 0; o < 7; o++) {
        if (eg[j][o] == '0' && s[i][o] == '1') {
          flag = 0;
          break;
        } else if (eg[j][o] != s[i][o]) {
          num++;
        }
      }
      if (!flag) continue;
      val[i][j] = num;
    }
  }
}
void fuck() {
  dp[n + 1][0] = 1;
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j < 10; j++) {
      if (val[i][j] == -1) continue;
      for (int s = 0; s <= k; s++) {
        dp[i][s + val[i][j]] |= dp[i + 1][s];
      }
    }
  }
  if (dp[1][k] == 0) {
    printf("-1\n");
  } else {
    string ans = "";
    for (int i = 1; i <= n; i++) {
      for (int j = 9; j >= 0; j--) {
        if (val[i][j] == -1) continue;
        if (dp[i + 1][k - val[i][j]]) {
          ans += to_string(j);
          k -= val[i][j];
          break;
        }
      }
    }
    cout << ans << endl;
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%s", s[i]);
  init();
  fuck();
  return 0;
}
