#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n{0}, k{0};
  cin >> n >> k;
  vector<string> numbers(n);
  for (int i = 0; i < n; i++) {
    cin >> numbers[i];
  }
  vector<string> digits(10);
  digits[0] = "1110111";
  digits[1] = "0010010";
  digits[2] = "1011101";
  digits[3] = "1011011";
  digits[4] = "0111010";
  digits[5] = "1101011";
  digits[6] = "1101111";
  digits[7] = "1010010";
  digits[8] = "1111111";
  digits[9] = "1111011";
  int dp[n + 1][k + 1];
  int dp_tracking[n + 1][k + 1];
  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < k + 1; j++) {
      dp[i][j] = -1;
      dp_tracking[i][j] = -1;
    }
  }
  dp_tracking[n][k] = 0;
  for (int i = n; i > 0; i--) {
    for (int val = k; val >= 0; val--) {
      if (dp_tracking[i][val] == -1) {
        continue;
      }
      for (int j = 0; j < 10; j++) {
        bool flag = true;
        int op{0};
        for (int k = 0; k < 7; k++) {
          if (numbers[i - 1][k] > digits[j][k]) {
            flag = false;
            break;
          }
          if (numbers[i - 1][k] < digits[j][k]) {
            op++;
          }
        }
        if (flag) {
          if (val < op) {
            continue;
          }
          if (i != 0 && j > dp[i - 1][val - op]) {
            dp_tracking[i - 1][val - op] = val;
            dp[i - 1][val - op] = j;
          }
        }
      }
    }
  }
  if (dp[0][0] == -1) {
    cout << "-1" << endl;
    return 0;
  }
  string ans;
  int value{0};
  for (int i = 0; i < n; i++) {
    ans.append(1, dp[i][value] + '0');
    value = dp_tracking[i][value];
  }
  cout << ans << endl;
  return 0;
}
