#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const long long linf = 0x3f3f3f3f3f3f3f3f;
string A[2100];
string dp[2100][2100];
int vis[2100][2100];
string m[10];
int n, k;
int g[260][20];
int a[2100];
string solve(int x, int y) {
  if (vis[x][y]) return dp[x][y];
  vis[x][y] = 1;
  if (x > n) {
    if (y == 0) return dp[x][y] = "0";
    return dp[x][y] = "-";
  }
  for (int j = 9; j >= 0; j--) {
    int z = g[a[x]][j];
    if (z != -1) {
      if (z > y) continue;
      solve(x + 1, y - z);
      if (dp[x + 1][y - z][0] == '-') continue;
      dp[x + 1][y - z].push_back(j + '0');
      return dp[x][y] = dp[x + 1][y - z];
    }
  }
  return dp[x][y] = "-";
}
int main() {
  m[0] = "1110111", m[1] = "0010010", m[2] = "1011101", m[3] = "1011011",
  m[4] = "0111010";
  m[5] = "1101011", m[6] = "1101111", m[7] = "1010010", m[8] = "1111111",
  m[9] = "1111011";
  for (int i = 0; i <= 127; i++) {
    string l;
    for (int j = 6; j >= 0; j--) {
      if ((1 << j) & i)
        l.push_back('1');
      else
        l.push_back('0');
    }
    for (int j = 0; j <= 9; j++) {
      int k = 0;
      bool ok = true;
      for (int z = 0; z < 7; z++) {
        if (l[z] == '1' && m[j][z] == '0')
          ok = false;
        else if (l[z] == '0' && m[j][z] == '1')
          k++;
      }
      if (!ok)
        g[i][j] = -1;
      else
        g[i][j] = k;
    }
  }
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    for (int j = 0; j < 7; j++) a[i] *= 2, a[i] += A[i][j] - '0';
  }
  string res = solve(1, k);
  if (res == "-")
    cout << -1 << "\n";
  else {
    reverse(res.begin(), res.end());
    res.pop_back();
    cout << res << "\n";
  }
  return 0;
}
