#include <bits/stdc++.h>
using namespace std;
int n, k;
string inp;
string nums[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                 "1101011", "1101111", "1010010", "1111111", "1111011"};
int bs[2001][7];
int digit[2001][10];
int dp[2001][2001][10];
int isPossible(int board, int rem, int num) {
  if (board > n) {
    if (rem == 0)
      return 1;
    else
      return 0;
  }
  if (dp[board][rem][num] != -1) return dp[board][rem][num];
  bool ok = false;
  for (int x = 9; x >= 0; x--) {
    if (ok) break;
    int l = digit[board][x];
    if (l != -1 && rem - l >= 0) {
      for (int y = 9; y >= 0; y--) {
        dp[board][rem][x] = isPossible(board + 1, rem - l, y);
        if (dp[board][rem][x] == 1) {
          ok = true;
          break;
        }
      }
    } else {
      dp[board][rem][x] = 0;
    }
  }
  return dp[board][rem][num];
}
void solve() {
  memset(dp, -1, sizeof dp);
  isPossible(1, k, 9);
  string res = "";
  int y = k;
  for (int x = 1; x <= n; x++) {
    while (true) {
      for (int z = 9; z >= 0; z--) {
        if (dp[x][y][z] == 1) {
          res += (char)(z + '0');
          y -= digit[x][z];
          break;
        }
      }
      break;
    }
  }
  if (res.length() == 0)
    cout << -1 << endl;
  else
    cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int x = 1; x <= n; x++) {
    cin >> inp;
    for (int y = 0; y < 7; y++) {
      bs[x][y] = (inp[y] - '0');
    }
  }
  for (int x = 1; x <= n; x++) {
    for (int y = 0; y < 10; y++) {
      bool ok = true;
      int tot = 0;
      for (int z = 0; z < 7; z++) {
        if (nums[y][z] - '0' == 1 && bs[x][z] == 0) {
          tot++;
        } else if (nums[y][z] - '0' == 0 && bs[x][z] == 1) {
          ok = false;
          break;
        }
      }
      if (ok)
        digit[x][y] = tot;
      else
        digit[x][y] = -1;
    }
  }
  solve();
}
