#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
template <class T>
inline T biton(T n, T pos) {
  return n | ((T)1 << pos);
}
template <class T>
inline T bitoff(T n, T pos) {
  return n & ~((T)1 << pos);
}
template <class T>
inline T ison(T n, T pos) {
  return (bool)(n & ((T)1 << pos));
}
template <class T>
inline T gcd(T a, T b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
inline int nxt() {
  int aaa;
  scanf("%d", &aaa);
  return aaa;
}
inline long long lxt() {
  long long aaa;
  scanf("%lld", &aaa);
  return aaa;
}
inline double dxt() {
  double aaa;
  scanf("%lf", &aaa);
  return aaa;
}
template <class T>
inline T bigmod(T p, T e, T m) {
  T ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % m;
    p = (p * p) % m;
  }
  return (T)ret;
}
const int inf = INT_MAX / 3;
vector<int> v, make = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123};
int n, k;
int memoization[2005][2005];
inline int Difference(int s, int n) {
  int cnt = 0;
  for (int i = 0; i < 7; i++) {
    if (ison(make[n], i)) {
      if (!ison(s, i)) {
        cnt++;
        s = biton(s, i);
      }
    }
  }
  if (cnt <= k && s == make[n]) {
    return cnt;
  } else
    return inf;
}
int isPossible(int pos, int value) {
  if (value < 0) {
    return 0;
  }
  if (pos >= n) {
    return value == 0;
  }
  int& ret = memoization[pos][value];
  if (ret != -1) {
    return ret;
  }
  ret = 0;
  for (int i = 9; i >= 0; i--) {
    int val = Difference(v[pos], i);
    if (val != inf) {
      ret |= isPossible(pos + 1, value - val);
    }
  }
  return ret;
}
void solve() {
  cin >> n >> k;
  int zero = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int num = 0;
    reverse(s.begin(), s.end());
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') num = biton(num, i);
    }
    v.push_back(num);
  }
  string ans = "";
  memset(memoization, -1, sizeof(memoization));
  for (int i = 0; i < n; i++) {
    bool ok = false;
    for (int num = 9; num >= 0; num--) {
      int kk = k;
      int dif = Difference(v[i], num);
      if (dif == inf) continue;
      kk -= dif;
      if (isPossible(i + 1, kk)) {
        k = kk;
        ok = true;
        ans += num + '0';
        break;
      }
    }
    if (!ok) {
      cout << -1 << "\n";
      return;
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.setf(ios::fixed);
  cout.precision(10);
  int tc = 1;
  while (tc--) {
    solve();
  }
  return 0;
}
