#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, m, f[N][N], len[N];
string a[N], num[10], ans;
pair<int, int> sum[N][10];
int main() {
  num[0] = "1110111";
  num[1] = "0010010";
  num[2] = "1011101";
  num[3] = "1011011";
  num[4] = "0111010";
  num[5] = "1101011";
  num[6] = "1101111";
  num[7] = "1010010";
  num[8] = "1111111";
  num[9] = "1111011";
  scanf("%d%d", &n, &m);
  int mm = m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 9; j >= 0; j--) {
      int flag = 1, tmp = 0;
      for (int k = 0; k < 7; k++) {
        if (a[i][k] == num[j][k]) continue;
        if (a[i][k] == '1' && num[j][k] == '0') {
          flag = 0;
          break;
        }
        tmp++;
      }
      if (flag == 1) sum[i][++len[i]] = make_pair(tmp, j);
    }
  }
  f[n + 1][0] = 1;
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= len[i]; j++)
      for (int k = sum[i][j].first; k <= m; k++)
        f[i][k] |= f[i + 1][k - sum[i][j].first];
  if (f[1][m] == 0) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= len[i]; j++) {
      int x = sum[i][j].first;
      if (mm < x) continue;
      if (f[i + 1][mm - x]) {
        char ch = sum[i][j].second + '0';
        ans += ch;
        mm -= x;
        break;
      }
    }
  }
  cout << ans;
  return 0;
}
