#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
inline void smax(int &x, int y) { x = max(x, y); }
inline void smin(int &x, int y) { x = min(x, y); }
ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); }
vector<string> rl = {"1110111", "0010010", "1011101", "1011011", "0111010",
                     "1101011", "1101111", "1010010", "1111111", "1111011"};
int findreq(string s, int num) {
  bitset<7> b(s);
  bitset<7> tm(rl[num]);
  bitset<7> o = b | tm;
  if (o != tm) return -1;
  bitset<7> xo = b ^ tm;
  return xo.count();
}
vector<vector<int> > dp;
vector<string> v;
int solve(int i, int k) {
  if (i == -1) {
    return (k == 0);
  }
  if (dp[i][k] != -1) return dp[i][k];
  int fin = 0;
  for (int j = 9; j >= 0; j--) {
    int res = findreq(v[i], j);
    if (res != -1 && k >= res) {
      int res2 = solve(i - 1, k - res);
      fin = res2 | fin;
    }
  }
  dp[i][k] = fin;
  return dp[i][k];
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  v.resize(n);
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    cin >> v[i];
  reverse(v.begin(), v.end());
  dp.resize(n, vector<int>(k + 1, -1));
  int res = solve(n - 1, k);
  if (res == 0) {
    cout << -1;
    exit(0);
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 9; j >= 0; j--) {
      int res = findreq(v[i], j);
      if (res != -1 && k >= res && solve(i - 1, k - res) == 1) {
        k -= res;
        cout << j;
        break;
      }
    }
  }
}
