text: #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>  
  #include <functional>
  #include <bits/stdc++.h>
  using namespace __gnu_pbds;
  using namespace std;
  typedef long long ll;
  typedef vector<int> vi;
  typedef vector<string> vs;
  typedef vector<long long> vl;
  typedef vector<vector<int>> vvi;
  typedef vector<vector<long long>> vvl;
  typedef pair<int,int> pt;
  typedef pair<long long ,long long> ptl;
  typedef set<int> si;
  typedef set<long long> sl;
  typedef unordered_set <int> usi;
  typedef unordered_set <long long> usl;
  typedef multiset<int> msi;
  typedef multiset<long long> msl;
  template <typename T>
  using indexed_set = tree<T, null_type, less<T>, 
  	rb_tree_tag, tree_order_statistics_node_update>;  
  // order_of_key: The number of items in a set that are strictly smaller than k
  // find_by_order: It returns an iterator to the ith largest element
  //Anubhaw Bhalotia https://github.com/anubhawbhalotia
  #define x first
  #define y second
  #define mp make_pair
  #define pb push_back
  #define lb lower_bound
  #define ub upper_bound
  #define beg(x) x.begin()
  #define en(x) x.end()
  #define all(x) x.begin(), x.end()
  #define f(i,s,n) for(int i=s;i<n;i++)
  #define fe(i,s,n) for(int i=s;i<=n;i++)
  #define fr(i,s,n) for(int i=s;i>n;i--)
  #define fre(i,s,n) for(int i=s;i>=n;i--)
  const int MOD = 998244353;
  template <typename T,typename U, typename V,typename W>
  auto operator+=(const pair<T,U> & l, pair<V,W> & r) 
  	-> pair<decltype(l.first+r.first),decltype(l.second+r.second)>                
  {                                                                                  
      return {l.first+r.first,l.second+r.second};                                    
  } 
  template <typename T,typename U, typename V,typename W>                            
  auto operator+(const pair<T,U> & l, pair<V,W> & r) 
  	-> pair<decltype(l.first+r.first),decltype(l.second+r.second)>                
  {                                                                                  
      return {l.first+r.first,l.second+r.second};                                    
  }
  template <typename T> T gcd(T a, T b) {return b == 0 ? a : gcd(b, a % b);}   
  int extendedEuclid(int a, int b, int *x, int *y){if(a == 0){*x = 0;*y = 1;
  	return b;}int x1, y1;int gcd = extendedEuclid(b % a, a, &x1, &y1);
  	*x = y1 - (b/a) * x1;*y = x1;return gcd;}
  map <int, string> m;
  int getTurnOn(string &s, int x)
  {
  	int c = 0;
  	f(i, 0, 7)
  	{
  		if(s[i] == '1' && m[x][i] == '0')
  			return -1;
  		if(s[i] == '0' && m[x][i] == '1')
  			c++;
  	}
  	return c;
  }
  int dp(vvi &DP, vs &s, int &n, int x, int y, string &ans)
  {
  	if(x == n)
  	{
  		if(y == 0)
  			return 1;
  		return 0;
  	}
  	// if(DP[x][y] == 1)
  	// 	return 0;
  	DP[x][y] = 1;
  	fre(i, 9, 0)
  	{
  		int z = getTurnOn(s[x], i);
  		if(z >= 0 && z <= y)
  		{
  			ans[x] = (i + 48);
  			int ret = dp(DP, s, n, x + 1, y - z, ans);
  			if(ret == 1)
  				return 1;
  		}
  	}
  	return 0;
  }	
  void solution(int t)
  {
  	int n, k;
  	cin>>n>>k;
  	vs s(n);
  	f(i, 0, n)
  	{
  		cin>>s[i];
  	}
  	vvi DP(n, vi(k + 1, 0));
  	string ans;
  	f(i, 0, n)
  	{
  		ans += ' ';
  	}
  	int z = dp(DP, s, n, 0, k, ans);
  	if(z == 0)
  		cout<<"-1"<<endl;
  	else
  		cout<<ans<<endl;
  }
  void testCase()
  {
  	m[0] = "1110111";
  	m[1] = "0010010";
  	m[2] = "1011101"; 
  	m[3] = "1011011";
  	m[4] = "0111010"; 
  	m[5] = "1101011";
  	m[6] = "1101111";
  	m[7] = "1010010";
  	m[8] = "1111111";
  	m[9] = "1111011";
  	int t = 1;
  	// cin>>t;
  	f(i, 0, t)
  	{
  		solution(i + 1);
  	}
  }
  int main()
  {
      ios_base::sync_with_stdio(false); 
      cin.tie(NULL);
      testCase();
  }   
  