#include <bits/stdc++.h>
using namespace std;
const long long INF = 2000000000000000000LL;
const int inf = 0x3f3f3f3f;
const long double EPS = 1e-9;
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.first < b.first) return 1;
  if (a.first == b.first) {
    if (a.second >= b.second) return 1;
  }
  return 0;
}
bool cmp2(pair<int, int> a, pair<int, int> b) {
  if (a.second > b.second) return 1;
  if (a.second == a.second) {
    if (a.first < b.first) return 1;
  }
  return 0;
}
bool cmp3(pair<int, int> a, pair<int, int> b) {
  if (a.first > b.first) return 1;
  if (a.first == b.first) {
    if (a.second > b.second) return 1;
  }
  return 0;
}
const int maxn = 1e5;
int change[maxn];
int main() {
  int n, k;
  string digit[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                    "1101011", "1101111", "1010010", "1111111", "1111011"};
  int cnt[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  cin >> n >> k;
  std::vector<string> str(n + 1);
  std::vector<string> mstr(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> mstr[i];
    str[i] = mstr[i];
  }
  std::vector<pair<int, int>> can_go[n + 1];
  std::vector<int> invalid;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      int digcnt = 0;
      int ck = 0;
      for (int d = 0; d < 7; d++) {
        if (mstr[i][d] == '1' && mstr[i][d] != digit[j][d]) ck = 1;
        if (mstr[i][d] == '1') digcnt++;
      }
      if (ck == 0) can_go[i].push_back({cnt[j] - digcnt, j});
    }
  }
  for (int i = 0; i < n; i++) {
    int ck = 0;
    for (int j = 0; j < 7; j++)
      if (mstr[i] == digit[j]) ck = 1;
    if (ck == 0) invalid.push_back(i);
  }
  for (int i = 0; i < n; i++) sort((can_go[i]).begin(), (can_go[i]).end(), cmp);
  bool flug = true;
  for (int i = 0; i < invalid.size(); i++) {
    int indx = invalid[i];
    if (can_go[indx][0].first > k) {
      flug = false;
      break;
    }
    change[indx] = can_go[indx][0].first;
    k -= can_go[indx][0].first;
    str[indx] = digit[can_go[indx][0].second];
  }
  if (flug == false) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++)
    sort((can_go[i]).begin(), (can_go[i]).end(), cmp2);
  std::vector<pair<int, int>> cngo[n + 1];
  for (int i = 0; i < n; i++) {
    cngo[i] = can_go[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < can_go[i].size(); j++) {
      if (digit[can_go[i][j].second] == str[i]) break;
      int cng = can_go[i][j].first - change[i];
      if (cng < 0) break;
      if (cng <= k) {
        change[i] += cng;
        k -= cng;
        str[i] = digit[can_go[i][j].second];
        break;
      }
    }
  }
  if (k > 0) {
    for (int i = 0; i < n; i++)
      sort((can_go[i]).begin(), (can_go[i]).end(), cmp3);
    for (int i = n - 1; i >= 0; i--) {
      if (n - i >= 3) {
        int l = i + 1, r = i + 2;
        while (l < n && r < n && k) {
          while (cngo[l].size() == 1) l++;
          while (cngo[r].size() == 1 || r == l) r++;
          if (r < l) swap(l, r);
          if (r != n && l != n)
            for (int j = 0; j < cngo[l].size(); j++) {
              int nk = k + change[l] + change[i + 2];
              for (int x = 0; x < cngo[r].size(); x++) {
                if (cngo[l][j].first + cngo[r][x].first == nk) {
                  str[l] = digit[cngo[l][j].second];
                  str[r] = digit[cngo[r][x].second];
                  k = 0;
                }
                if (k == 0) break;
              }
              if (k == 0) break;
            }
          r++;
        }
      }
      if (k == 0) break;
      for (int j = 0; j < can_go[i].size(); j++) {
        if (digit[can_go[i][j].second] == str[i]) continue;
        int cng = can_go[i][j].first - change[i];
        if (cng < 0) break;
        if (cng > k) continue;
        k -= cng;
        change[i] += cng;
        str[i] = digit[can_go[i][j].second];
      }
      if (k == 0) break;
    }
  }
  if (k > 0 || flug == false) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      if (str[i] == digit[j]) cout << j;
  }
  cout << endl;
  return 0;
}
