#include <bits/stdc++.h>
using namespace std;
char FF[2001][2001];
int n;
vector<vector<bool> > A;
vector<vector<int> > B;
char F(int q, int w) {
  if (w < 0) return 0;
  if (FF[q][w] == 2) {
    if (q == n) {
      FF[q][w] = (w == 0) ? 1 : 0;
      return FF[q][w];
    }
    FF[q][w] = 0;
    for (int i = 0; i < 8; i++)
      if (A[q][i])
        if (F(q + 1, w - i) == 1) {
          FF[q][w] = 1;
          break;
        }
  }
  return FF[q][w];
}
void G(int q, int w) {
  if (q == n) return;
  for (int i = 9; i >= 0; i--)
    if (B[q][i] != -1)
      if (F(q + 1, w - B[q][i]) == 1) {
        printf("%d", i);
        return G(q + 1, w - B[q][i]);
      }
}
int main() {
  int C[10] = {1110111, 10010,   1011101, 1011011, 111010,
               1101011, 1101111, 1010010, 1111111, 1111011};
  int k;
  scanf("%d%d", &n, &k);
  A.assign(n, vector<bool>(8, false));
  B.assign(n, vector<int>(10, -1));
  for (int i = 0; i < n; i++) {
    int q;
    scanf("%d", &q);
    for (int j = 0; j < 10; j++)
      if (q <= C[j]) {
        int k1 = 0;
        int w = C[j] - q;
        while (w > 0) {
          if (w % 10 > 1) break;
          k1 += w % 10;
          w /= 10;
        }
        if (w > 0) continue;
        B[i][j] = k1;
        A[i][k1] = true;
      }
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= k; j++) FF[i][j] = 2;
  if (F(0, k) == 0)
    printf("-1");
  else
    G(0, k);
  printf("\n");
  return 0;
}
