#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int in() {
  int x;
  cin >> x;
  return x;
}
long long lin() {
  long long x;
  cin >> x;
  return x;
}
string stin() {
  string s;
  cin >> s;
  return s;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
vector<int> iota(int n) {
  vector<int> a(n);
  iota(begin(a), end(a), 0);
  return a;
}
void print() { putchar(' '); }
void print(bool a) { cout << a; }
void print(int a) { cout << a; }
void print(long long a) { cout << a; }
void print(char a) { cout << a; }
void print(string& a) { cout << a; }
void print(double a) { cout << a; }
template <class T>
void print(const vector<T>&);
template <class T, size_t size>
void print(const array<T, size>&);
template <class T, class L>
void print(const pair<T, L>& p);
template <class T, size_t size>
void print(const T (&)[size]);
template <class T>
void print(const vector<T>& a) {
  if (a.empty()) return;
  print(a[0]);
  for (auto i = a.begin(); ++i != a.end();) {
    cout << " ";
    print(*i);
  }
  cout << endl;
}
template <class T>
void print(const deque<T>& a) {
  if (a.empty()) return;
  print(a[0]);
  for (auto i = a.begin(); ++i != a.end();) {
    cout << " ";
    print(*i);
  }
}
template <class T, size_t size>
void print(const array<T, size>& a) {
  print(a[0]);
  for (auto i = a.begin(); ++i != a.end();) {
    cout << " ";
    print(*i);
  }
}
template <class T, class L>
void print(const pair<T, L>& p) {
  cout << '(';
  print(p.first);
  cout << ",";
  print(p.second);
  cout << ')';
}
template <class T, size_t size>
void print(const T (&a)[size]) {
  print(a[0]);
  for (auto i = a; ++i != end(a);) {
    cout << " ";
    print(*i);
  }
}
template <class T>
void print(const T& a) {
  cout << a;
}
int out() {
  putchar('\n');
  return 0;
}
template <class T>
int out(const T& t) {
  print(t);
  putchar('\n');
  return 0;
}
template <class Head, class... Tail>
int out(const Head& head, const Tail&... tail) {
  print(head);
  putchar(' ');
  out(tail...);
  return 0;
}
long long gcd(long long a, long long b) {
  while (b) {
    long long c = b;
    b = a % b;
    a = c;
  }
  return a;
}
long long lcm(long long a, long long b) {
  if (!a || !b) return 0;
  return a * b / gcd(a, b);
}
const int INF = 1061109567;
const long long LINF = 4557430888798830399LL;
const int d0 = 0x77;
const int d1 = 0x12;
const int d2 = 0x5d;
const int d3 = 0x5b;
const int d4 = 0x3a;
const int d5 = 0x6b;
const int d6 = 0x6f;
const int d7 = 0x52;
const int d8 = 0x7f;
const int d9 = 0x7b;
int digit[2001];
int fix[2001];
bool visit[2001][2001];
int mapper[10] = {d0, d1, d2, d3, d4, d5, d6, d7, d8, d9};
int n, k;
int trans(int a, int b) {
  if ((a & b) != a) {
    return -1;
  } else {
    return __builtin_popcount(a ^ b);
  }
}
bool dfs(int left, int pos) {
  if (visit[left][pos]) return false;
  visit[left][pos] = true;
  int cur = digit[pos];
  for (long long i = 9; i >= 0; i--) {
    int diff = trans(cur, mapper[i]);
    if (diff >= 0 && diff <= left) {
      fix[pos] = i;
      if (pos == n && left == diff) {
        return true;
      } else if (diff <= left && pos < n) {
        bool result = dfs(left - diff, pos + 1);
        if (result) return true;
      }
    }
  }
  return false;
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  n = in();
  k = in();
  for (long long i = 1; i <= n; ++i) {
    string tmp = stin();
    digit[i] = stoi(tmp, 0, 2);
  }
  if (!dfs(k, 1)) {
    cout << -1 << '\n';
  } else {
    for (int i = 1; i <= n; i++) {
      cout << fix[i];
    }
  }
}
