#include <iostream>

int t[10000];
int main(){
  int n, m, k;
  std::cin >> n >> m >> k;
  for (int i=0; i<n; i++){
    for (int j=0; j<m; j++){
      std::cin >> t[100*i+j];
    }
  }
  int ans=1000000;
  for (int j=0; j<m; j++){
    int dc=0;
    for (int j2=0; j2<m; j2++){
      int c=0;
      for (int i=0; i<n; i++){
	if (t[100*i+j]==t[100*i+j2]) c++;
      }
      dc+=std::min(c, n-c);
    }
    ans=std::min(ans, dc);
  }
  if (ans>k){
    std::cout << -1;
  }else{
    std::cout << ans;
  }

}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

const int maxn = 100 + 13;

int n, m, k;

int a[maxn][maxn];
int trow[maxn];

int minn;

int diff(int *a, int *b)
{
	int res = 0;
	for (int i = 0; i < m; ++ i)
		if (a[i] != b[i])
			res ++;
	if (m - res < res) return m - res;
	return res;
}

void change(int *ta, int i, int tk)
{
	if (tk == 0 || i >= m)
	{
		int tsum = 0;
		for (int j = 0; j < n; ++ j)
			tsum += diff(ta, a[j]);
		if (tsum < minn)
			minn = tsum;
		return ;
	}
	ta[i] = 1 - ta[i];
	change(ta, i + 1, k - 1);
	ta[i] = 1 - ta[i];
	change(ta, i + 1, k);
}

int main()
{
	//freopen("data.in", "r", stdin);
	//freopen("data.out", "w", stdout);

	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; ++ i)
		for (int j = 0; j < m; ++ j)
		{
			int ta;
			scanf("%d", &ta);
			if (n > m) a[i][j] = ta;
			else a[j][i] = ta;
		}
	if (n < m)
	{
		int t = n;n = m; m = t;
	}

	minn = k + 1;
	for (int i = 0; i < n; ++ i)
	{
		memcpy(trow, a[i], sizeof(trow));
		for (int j = 0; j <= k/n && j < m; ++ j)
			change(trow, 0, j);
	}

	if (minn > k) puts("-1");
	else printf("%d\n", minn);

    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

const int maxn = 100 + 13;

int n, m, k;

int a[maxn][maxn];
int trow[maxn];

int minn;

int diff(int *a, int *b)
{
	int res = 0;
	for (int i = 0; i < m; ++ i)
		if (a[i] != b[i])
			res ++;
	if (m - res < res) return m - res;
	return res;
}

void change(int *ta, int i, int tk)
{
	if (tk == 0 || i >= m)
	{
		int tsum = 0;
		for (int j = 0; j < n; ++ j)
			tsum += diff(ta, a[j]);
		if (tsum < minn)
			minn = tsum;
		return ;
	}
	ta[i] = 1 - ta[i];
	change(ta, i + 1, k - 1);
	ta[i] = 1 - ta[i];
	change(ta, i + 1, k);
}

int main()
{
	//freopen("data.in", "r", stdin);
	//freopen("data.out", "w", stdout);

	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; ++ i)
		for (int j = 0; j < m; ++ j)
		{
			int ta;
			scanf("%d", &ta);
			if (n > m) a[i][j] = ta;
			else a[j][i] = ta;
		}
	if (n < m)
	{
		int t = n;n = m; m = t;
	}

	minn = k + 1;
	for (int i = 0; i < n; ++ i)
	{
		memcpy(trow, a[i], sizeof(trow));
		for (int j = 0; j <= k/n && j < m; ++ j)
			change(trow, 0, k);
	}

	if (minn > k) puts("-1");
	else printf("%d\n", minn);

    return 0;
}


#include<stdio.h>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<set>
#include<string>
#include<algorithm>
#define LL __int64
#define MOD 1000000007
#define M 110
#define Min(x,y) (x)>(y)?(y):(x)
using namespace std;
int ans;
int n,m,k;
int a[110][110],b[110],c[110];
int main()
{
    int  i,j,z,T,d;
    //freopen("D:\\o.txt","r",stdin);
    while(~scanf("%d%d%d",&n,&m,&k))
    {
        int ans=1234567;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
                scanf("%d",&a[i][j]);
        }
        for(i=0;i<n;i++)
        {
            int minn=0;
            for(z=0;z<m;z++)
                b[z]=a[i][z]^1,c[z]=a[i][z]^0;
            for(j=0;j<n;j++)
            {
                int cnt1=0,cnt2=0;
                for(z=0;z<m;z++)
                {
                    if(b[z]!=a[j][z])cnt1++;
                    if(c[z]!=a[j][z])cnt2++;
                }
                minn+=Min(cnt1,cnt2);
            }
            ans=Min(minn,ans);
        }
        for(j=0;j<m;j++)
        {
            int minn=0;
            for(z=0;z<n;z++)
                b[z]=a[z][j]^1,c[z]=a[z][j]^0;
            for(i=0;i<m;i++)
            {
                int cnt1=0,cnt2=0;
                for(z=0;z<n;z++)
                {
                    if(b[z]!=a[z][i])cnt1++;
                    if(c[z]!=a[z][i])cnt2++;
                }
                minn+=Min(cnt1,cnt2);
            }
            ans=Min(minn,ans);
        }
        if(ans>k)puts("-1");
        else printf("%d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<set>
#include<string>
#include<algorithm>
#define LL __int64
#define MOD 1000000007
#define M 110
using namespace std;
int ans;
int n,m,k;
int a[110][110],vis[110][110];
int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
int up=1,down=-1,Left=0,Right=m-1,tot;
void dfs(int x,int y)
{
    int i;
    vis[x][y]=1;
    tot++;
    if(x>up)up=x;
    if(x<down)down=x;
    if(y<Left)Left=y;
    if(y>Right)Right=y;
    for(i=0;i<4;i++)
    {
        int xx=x+dx[i],yy=dy[i]+y;
        if(xx<0||xx>=n||yy<0||yy>=m||vis[xx][yy]||!a[xx][yy])continue;
        dfs(xx,yy);
    }
}
int main()
{
    int  i,j,z,T,d;
    //freopen("D:\\o.txt","r",stdin);
    while(~scanf("%d%d%d",&n,&m,&k))
    {
        int ans=0;
        memset(vis,0,sizeof(vis));
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
                scanf("%d",&a[i][j]);
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                if(a[i][j]==1&&!vis[i][j])
                {
                    up=0,down=n-1,Left=m-1,Right=0;
                    tot=0;
                    dfs(i,j);
                    ans+=(up-down+1)*(Right-Left+1)-tot;
                }
            }
        }
        if(ans>k)
            puts("-1");
        else
            printf("%d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<set>
#include<string>
#include<algorithm>
#define LL __int64
#define MOD 1000000007
#define M 110
using namespace std;
int ans;
int n,m,k;
int a[110][110],vis[110][110];
int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
int up=1,down=-1,Left=0,Right=m-1,tot;
void dfs(int x,int y)
{
    int i;
    vis[x][y]=1;
    tot++;
    if(x>up)up=x;
    if(x<down)down=x;
    if(y<Left)Left=y;
    if(y>Right)Right=y;
    for(i=0;i<4;i++)
    {
        int xx=x+dx[i],yy=dy[i]+y;
        if(xx<0||xx>=n||yy<0||yy>=m||vis[xx][yy]||!a[xx][yy])continue;
        dfs(xx,yy);
    }
}
int main()
{
    int  i,j,z,T,d;
    //freopen("D:\\o.txt","r",stdin);
    //while(~)
    {
        scanf("%d%d%d",&n,&m,&k);
        ans=0;
        memset(vis,0,sizeof(vis));
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
                scanf("%d",&a[i][j]);
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                if(a[i][j]==1&&!vis[i][j])
                {
                    up=0,down=n-1,Left=m-1,Right=0;
                    tot=0;
                    dfs(i,j);
                    ans+=(up-down+1)*(Right-Left+1)-tot;
                }
            }
        }
        if(ans>k)
            puts("-1");
        else
            printf("%d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<set>
#include<string>
#include<algorithm>
#define LL __int64
#define MOD 1000000007
#define M 110
using namespace std;
int ans=0;
int n,m,k;
int a[110][110],vis[110][110];
struct node
{
    int x,y;
}u;
vector<int>res[110];
int dx[]={-1,-1,0,1,1,1,0,-1},dy[]={0,1,1,1,0,-1,-1,-1};
int up=1,down=-1,Left=0,Right=m-1,tot;
void dfs(int x,int y)
{
    int i;
    res[x].push_back(y);
    vis[x][y]=1;
    tot++;
    if(x>up)up=x;
    if(x<down)down=x;
    if(y<Left)Left=y;
    if(y>Right)Right=y;
    for(i=0;i<8;i++)
    {
        int xx=x+dx[i],yy=dy[i]+y;
        if(xx<0||xx>=n||yy<0||yy>=m||vis[xx][yy]||!a[xx][yy])continue;
        dfs(xx,yy);
    }
}
int main()
{
    int  i,j,z,T,d;
    //freopen("D:\\o.txt","r",stdin);
    while(~scanf("%d%d%d",&n,&m,&k))
    {
        memset(vis,0,sizeof(vis));
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
                scanf("%d",&a[i][j]);
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                if(a[i][j]==1&&!vis[i][j])
                {
                    up=0,down=n-1,Left=m-1,Right=0;
                    tot=0;
                    dfs(i,j);
                    ans+=(up-down+1)*(Right-Left+1)-tot;
                }
            }
        }
        if(ans>k)
            puts("-1");
        else
            printf("%d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<set>
#include<string>
#include<algorithm>
#define LL __int64
#define MOD 1000000007
#define M 110
#define Min(x,y) (x)>(y)?(y):(x)
using namespace std;
int ans;
int n,m,k;
int a[110][110],b[110],c[110];
int calc()
{
    int i,j,z,res=0;
    for(i=0;i<m;i++)
    {
        int cnt1=0;
        for(z=0;z<n;z++)
            if(b[z]!=a[z][i])cnt1++;
            res+=Min(cnt1,n-cnt1);
    }
    return res;
}
void dfs(int x)
{
    if(x==n)
    {
        ans=Min(calc(),ans);
        return ;
    }
    b[x]=0;
    dfs(x+1);
    b[x]=1;
    dfs(x+1);
}
int main()
{
    int  i,j,z,T,d;
    //freopen("D:\\o.txt","r",stdin);
    while(~scanf("%d%d%d",&n,&m,&k))
    {
        ans=1234567;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
                scanf("%d",&a[i][j]);
        }
        if(n>k)
        {
            for(j=0;j<m;j++)
            {
                int minn=0;
                for(z=0;z<n;z++)
                    b[z]=a[z][j]^1;
                ans=Min(calc(),ans);
            }
        }
        else dfs(0);
        if(ans>k)puts("-1");
        else printf("%d\n",ans);
    }
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <string>

using namespace std;

typedef map< string, size_t > CtMap;

size_t ham_dist( const string &a, const string &b ) {
	size_t ct = 0;
	for( size_t i = 0; i < a.size(); ++i )
		if( a[i] != b[i] )
			++ct;
	return ct;
}

string opp( const string &a ) {
	string r = "";
	for( size_t i = 0; i < a.size(); ++i )
		r += (a[i] == '0' ? "1" : "0");
	return r;
}

string read_line( size_t m ) {
	string r;
	for( size_t j = 0; j < m; ++j ) {
		char c[2]; cin >> c;
		r += string(c);
	}
	return r;
}

string string_from_int( size_t len, size_t z ) {
	string o;
	for( size_t i = 0; i < len; ++i ) {
		if( z & (1 << i) ) o += "1";
		else o += "0";
	}
	return o;
}

int main() {
	size_t n, m, k; cin >> n >> m >> k;
	CtMap counts;
	vector<string> mat;
	mat.reserve(n);
	for( size_t i = 0; i < n; ++i ) {
		string l = read_line(m);
		mat.push_back( l );
	}
	if( n < m ) {
		vector<string> newmat = mat;
		swap(n,m);
		mat.clear(); mat.reserve(n);
		for( size_t i = 0; i < n; ++i ) {
			string p;
			for( size_t j = 0; j < m; ++j ) {
				p += newmat[j][i];
			}
			mat.push_back(p);
		}
	}
	for( size_t i = 0; i < n; ++i ) {
		string &l = mat[i];
		if( counts.find(l) == counts.end() ) counts[l] = 0;
		++counts[l];
	}
	bool feasible = false;
	if( counts.size() <= k ) {
		if( n < k ) {
			for( size_t z = 0; z < ((size_t)1 << m); ++z ) {
				string l = string_from_int(m,z);
				if( counts.find(l) == counts.end() ) counts[l] = 0;
			}
		}
		for( CtMap::iterator it = counts.begin(); it != counts.end(); ++it ) {
			size_t cost = 0;
			for( CtMap::iterator jt = counts.begin(); jt != counts.end(); ++jt ) {
				if( jt->second == 0 ) continue;
				size_t cost_per = ham_dist(it->first, jt->first);
				cost_per = min(cost_per, ham_dist(opp(it->first), jt->first));
				cost += cost_per * jt->second;
			}
			if( cost <= k ) {
				feasible = true;
				k = cost;
			}
		}
	}
	if( !feasible ) {
		cout << "-1" << endl;
	}
	else {
		cout << k << endl;
	}
	return 0;
}


#include <iostream>
#include <stack>
#include <map>

using namespace std;

struct guess_st {
	size_t i, j;
	size_t v;
	size_t n_changes;
};

const size_t MAXN = 200;

int main() {
	size_t n, m, k; cin >> n >> m >> k;
	stack< guess_st > guesses;
	size_t bd[MAXN][MAXN];
	size_t tmp_bd[MAXN][MAXN];
	for( size_t i = 0; i < n; ++i )
	for( size_t j = 0; j < m; ++j ) {
		cin >> bd[i][j];
		tmp_bd[i][j] = bd[i][j];
	}
	size_t n_changes = 0;
	size_t min_changes = k + 1;
	bool possible = true;
	for( size_t i = 0; possible && i < n; ++i )
	for( size_t j = 0; possible && j < m; ++j ) {
		if( i > 0 && j > 0 ) {
			size_t c, l, u;
			c = tmp_bd[i-1][j-1]; l = tmp_bd[i][j-1]; u = tmp_bd[i-1][j];
			size_t v = (c+l+u) % 2;
			if( bd[i][j] != v ) { ++n_changes; }
			tmp_bd[i][j] = v;
		}
		else {
			guess_st g;
			g.i = i; g.j = j;
			g.v = bd[i][j];
			g.n_changes = n_changes;
			guesses.push( g );
		}
		if( i == n-1 && j == m-1 && n_changes <= min_changes ) {
			min_changes = min(min_changes, n_changes);
			n_changes = min_changes + 1; // force reset
		}
		if( n_changes > min_changes ) {
			while( !guesses.empty() && (guesses.top().n_changes == k || guesses.top().v != bd[guesses.top().i][guesses.top().j]) ) guesses.pop();
			if( guesses.empty() ) { possible = false; break; }
			i = guesses.top().i;
			j = guesses.top().j;
			tmp_bd[i][j] = guesses.top().v = 1 - bd[i][j];
			++guesses.top().n_changes;
			n_changes = guesses.top().n_changes;
		}
	}
	if( !possible && min_changes == k+1 ) {
		cout << "-1" << endl;
	}
	else {
		cout << min_changes << endl;
	}
	return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <string>

using namespace std;

typedef map< string, size_t > CtMap;

size_t ham_dist( const string &a, const string &b ) {
	size_t ct = 0;
	for( size_t i = 0; i < a.size(); ++i )
		if( a[i] != b[i] )
			++ct;
	return ct;
}

string opp( const string &a ) {
	string r = "";
	for( size_t i = 0; i < a.size(); ++i )
		r += (a[i] == '0' ? "1" : "0");
	return r;
}

string read_line( size_t m ) {
	string r;
	for( size_t j = 0; j < m; ++j ) {
		char c[2]; cin >> c;
		r += string(c);
	}
	return r;
}

string string_from_int( size_t len, size_t z ) {
	string o;
	for( size_t i = 0; i < len; ++i ) {
		if( z & (1 << i) ) o += "1";
		else o += "0";
	}
	return o;
}

int main() {
	size_t n, m, k; cin >> n >> m >> k;
	CtMap counts;
	vector<string> mat;
	mat.reserve(n);
	for( size_t i = 0; i < n; ++i ) {
		string l = read_line(m);
		mat.push_back( l );
	}
	if( n < m ) {
		vector<string> newmat = mat;
		swap(n,m);
		mat.clear(); mat.reserve(n);
		for( size_t i = 0; i < n; ++i ) {
			string p;
			for( size_t j = 0; j < m; ++j ) {
				p += newmat[j][i];
			}
			mat.push_back(p);
		}
	}
	for( size_t i = 0; i < n; ++i ) {
		string &l = mat[i];
		if( counts.find(l) == counts.end() ) counts[l] = 0;
		++counts[l];
	}
	bool feasible = false;
	if( counts.size() <= k+2 ) {
		if( n <= k ) {
			for( size_t z = 0; z < ((size_t)1 << m); ++z ) {
				string l = string_from_int(m,z);
				if( counts.find(l) == counts.end() ) counts[l] = 0;
			}
		}
		for( CtMap::iterator it = counts.begin(); it != counts.end(); ++it ) {
			size_t cost = 0;
			for( CtMap::iterator jt = counts.begin(); jt != counts.end(); ++jt ) {
				if( jt->second == 0 ) continue;
				size_t cost_per = ham_dist(it->first, jt->first);
				cost_per = min(cost_per, ham_dist(opp(it->first), jt->first));
				cost += cost_per * jt->second;
			}
			if( cost <= k ) {
				feasible = true;
				k = cost;
			}
		}
	}
	if( !feasible ) {
		cout << "-1" << endl;
	}
	else {
		cout << k << endl;
	}
	return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <string>

using namespace std;

typedef map< string, size_t > CtMap;

size_t ham_dist( const string &a, const string &b ) {
	size_t ct = 0;
	for( size_t i = 0; i < a.size(); ++i )
		if( a[i] != b[i] )
			++ct;
	return ct;
}

string opp( const string &a ) {
	string r = "";
	for( size_t i = 0; i < a.size(); ++i )
		r += (a[i] == '0' ? "1" : "0");
	return r;
}

string read_line( size_t m ) {
	string r;
	for( size_t j = 0; j < m; ++j ) {
		char c[2]; cin >> c;
		r += string(c);
	}
	return r;
}

string string_from_int( size_t len, size_t z ) {
	string o;
	for( size_t i = 0; i < len; ++i ) {
		if( z & (1 << i) ) o += "1";
		else o += "0";
	}
	return o;
}

int main() {
	size_t n, m, k; cin >> n >> m >> k;
	CtMap counts;
	vector<string> mat;
	mat.reserve(n);
	for( size_t i = 0; i < n; ++i ) {
		string l = read_line(m);
		mat.push_back( l );
	}
	if( n < m ) {
		vector<string> newmat = mat;
		swap(n,m);
		mat.clear(); mat.reserve(n);
		for( size_t i = 0; i < n; ++i ) {
			string p;
			for( size_t j = 0; j < m; ++j ) {
				p += newmat[j][i];
			}
			mat.push_back(p);
		}
	}
	for( size_t i = 0; i < n; ++i ) {
		string &l = mat[i];
		if( counts.find(l) == counts.end() ) counts[l] = 0;
		++counts[l];
	}
	bool feasible = false;
	if( counts.size() <= k+2 ) {
		if( n < k ) {
			for( size_t z = 0; z < ((size_t)1 << m); ++z ) {
				string l = string_from_int(m,z);
				if( counts.find(l) == counts.end() ) counts[l] = 0;
			}
		}
		for( CtMap::iterator it = counts.begin(); it != counts.end(); ++it ) {
			size_t cost = 0;
			for( CtMap::iterator jt = counts.begin(); jt != counts.end(); ++jt ) {
				if( jt->second == 0 ) continue;
				size_t cost_per = ham_dist(it->first, jt->first);
				cost_per = min(cost_per, ham_dist(opp(it->first), jt->first));
				cost += cost_per * jt->second;
			}
			if( cost <= k ) {
				feasible = true;
				k = cost;
			}
		}
	}
	if( !feasible ) {
		cout << "-1" << endl;
	}
	else {
		cout << k << endl;
	}
	return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <string>

using namespace std;

typedef map< string, size_t > CtMap;

size_t ham_dist( const string &a, const string &b ) {
	size_t ct = 0;
	for( size_t i = 0; i < a.size(); ++i )
		if( a[i] != b[i] )
			++ct;
	return ct;
}

string opp( const string &a ) {
	string r = "";
	for( size_t i = 0; i < a.size(); ++i )
		r += (a[i] == '0' ? "1" : "0");
	return r;
}

string read_line( size_t m ) {
	string r;
	for( size_t j = 0; j < m; ++j ) {
		char c[2]; cin >> c;
		r += string(c);
	}
	return r;
}

string string_from_int( size_t len, size_t z ) {
	string o;
	for( size_t i = 0; i < len; ++i ) {
		if( z & (1 << i) ) o += "1";
		else o += "0";
	}
	return o;
}

int main() {
	size_t n, m, k; cin >> n >> m >> k;
	CtMap counts;
	vector<string> mat;
	mat.reserve(n);
	for( size_t i = 0; i < n; ++i ) {
		string l = read_line(m);
		mat.push_back( l );
	}
	if( n < m ) {
		vector<string> newmat = mat;
		swap(n,m);
		mat.clear(); mat.reserve(n);
		for( size_t i = 0; i < n; ++i ) {
			string p;
			for( size_t j = 0; j < m; ++j ) {
				p += newmat[j][i];
			}
			mat.push_back(p);
		}
	}
	for( size_t i = 0; i < n; ++i ) {
		string &l = mat[i];
		if( counts.find(l) == counts.end() ) counts[l] = 0;
		++counts[l];
	}
	bool feasible = false;
	if( counts.size() <= 2*k ) {
		if( n < k ) {
			for( size_t z = 0; z < ((size_t)1 << m); ++z ) {
				string l = string_from_int(m,z);
				if( counts.find(l) == counts.end() ) counts[l] = 0;
			}
		}
		for( CtMap::iterator it = counts.begin(); it != counts.end(); ++it ) {
			size_t cost = 0;
			for( CtMap::iterator jt = counts.begin(); jt != counts.end(); ++jt ) {
				if( jt->second == 0 ) continue;
				size_t cost_per = ham_dist(it->first, jt->first);
				cost_per = min(cost_per, ham_dist(opp(it->first), jt->first));
				cost += cost_per * jt->second;
			}
			if( cost <= k ) {
				feasible = true;
				k = cost;
			}
		}
	}
	if( !feasible ) {
		cout << "-1" << endl;
	}
	else {
		cout << k << endl;
	}
	return 0;
}


#include <iostream>
#include <stack>
#include <map>

using namespace std;

struct guess_st {
	size_t i, j;
	size_t v;
	size_t n_changes;
};

const size_t MAXN = 200;

int main() {
	size_t n, m, k; cin >> n >> m >> k;
	stack< guess_st > guesses;
	size_t bd[MAXN][MAXN];
	size_t tmp_bd[MAXN][MAXN];
	for( size_t i = 0; i < n; ++i )
	for( size_t j = 0; j < m; ++j ) {
		cin >> bd[i][j];
		tmp_bd[i][j] = bd[i][j];
	}
	size_t n_changes = 0;
	size_t min_changes = k;
	bool possible = true;
	for( size_t i = 0; possible && i < n; ++i )
	for( size_t j = 0; possible && j < m; ++j ) {
		if( i > 0 && j > 0 ) {
			size_t c, l, u;
			c = tmp_bd[i-1][j-1]; l = tmp_bd[i][j-1]; u = tmp_bd[i-1][j];
			size_t v = (c+l+u) % 2;
			if( bd[i][j] != v ) { ++n_changes; }
			tmp_bd[i][j] = v;
		}
		else {
			guess_st g;
			g.i = i; g.j = j;
			g.v = bd[i][j];
			g.n_changes = n_changes;
			guesses.push( g );
		}
		if( i == n-1 && j == m-1 && n_changes <= k ) {
			min_changes = min(min_changes, n_changes);
			while( !guesses.empty() && (guesses.top().n_changes >= n_changes) ) guesses.pop();
			if( guesses.empty() ) { i = n; j = m; break; }
			i = guesses.top().i;
			j = guesses.top().j;
			tmp_bd[i][j] = guesses.top().v = 1 - bd[i][j];
			++guesses.top().n_changes;
			n_changes = guesses.top().n_changes;
		}
		if( n_changes > k ) {
			while( !guesses.empty() && (guesses.top().n_changes == k || guesses.top().v != bd[guesses.top().i][guesses.top().j]) ) guesses.pop();
			if( guesses.empty() ) { possible = false; break; }
			i = guesses.top().i;
			j = guesses.top().j;
			tmp_bd[i][j] = guesses.top().v = 1 - bd[i][j];
			++guesses.top().n_changes;
			n_changes = guesses.top().n_changes;
		}
	}
	if( !possible ) {
		cout << "-1" << endl;
	}
	else {
		cout << min_changes << endl;
	}
	return 0;
}


#include <iostream>
#include <stack>
#include <map>

using namespace std;

struct guess_st {
	size_t i, j;
	size_t v;
	size_t n_changes;
};

const size_t MAXN = 200;

int main() {
	size_t n, m, k; cin >> n >> m >> k;
	stack< guess_st > guesses;
	size_t bd[MAXN][MAXN];
	size_t tmp_bd[MAXN][MAXN];
	for( size_t i = 0; i < n; ++i )
	for( size_t j = 0; j < m; ++j ) {
		cin >> bd[i][j];
		tmp_bd[i][j] = bd[i][j];
	}
	size_t n_changes = 0;
	size_t min_changes = k;
	bool possible = true;
	for( size_t i = 0; possible && i < n; ++i )
	for( size_t j = 0; possible && j < m; ++j ) {
		if( i > 0 && j > 0 ) {
			size_t c, l, u;
			c = tmp_bd[i-1][j-1]; l = tmp_bd[i][j-1]; u = tmp_bd[i-1][j];
			size_t v = (c+l+u) % 2;
			if( bd[i][j] != v ) { ++n_changes; }
			tmp_bd[i][j] = v;
		}
		else {
			guess_st g;
			g.i = i; g.j = j;
			g.v = bd[i][j];
			g.n_changes = n_changes;
			guesses.push( g );
		}
		if( i == n-1 && j == m-1 && n_changes <= k ) {
			min_changes = min(min_changes, n_changes);
		}
		if( n_changes > k ) {
			while( !guesses.empty() && (guesses.top().n_changes == k || guesses.top().v != bd[guesses.top().i][guesses.top().j]) ) guesses.pop();
			if( guesses.empty() ) { possible = false; break; }
			i = guesses.top().i;
			j = guesses.top().j;
			tmp_bd[i][j] = guesses.top().v = 1 - bd[i][j];
			++guesses.top().n_changes;
			n_changes = guesses.top().n_changes;
		}
	}
	if( !possible ) {
		cout << "-1" << endl;
	}
	else {
		cout << min_changes << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e8 + 7)
using namespace std;

int num[105][105], n, m, k, ans;

int get1(int a)
{
    int res = 0;
    for(int i = 1;i <= n;i++)
    {
        if(i != a)
        {
            int res1 = 0, res2 = 0;
            for(int j = 1;j <= m;j++)
            {
                if(num[i][j] != num[a][j])
                    res1++;
                if(num[i][j] == num[a][j])
                    res2++;
            }
            res += min(res1, res2);
        }
    }
    return res;
}

int main()
{
    ans = inf;
    scanf("%d%d%d", &n, &m, &k);
    for(int i = 1;i <= n;i++)
        for(int j = 1;j <= m;j++)
            scanf("%d", &num[i][j]);
    if(n > k)
    {
        for(int i = 1;i <= n;i++)
            ans = min(ans, get1(i));
    }
    else
    {
        for(int i = 0;i < (1<<n);i++)
        {
            int res1 = 0, res2 = 0, res = 0;
            for(int j = 1;j <= n;j++)
            {
                if((num[j][1]&&(i&(1<<(j - 1))))||(!num[j][1]&&!(i&(1<<(j - 1)))))
                    res1++;
                else
                    res2++;
            }
            res += min(res1, res2);
            for(int j = 2;j <= m;j++)
            {
                res1 = 0, res2 = 0;
                for(int k = 1;k <= n;k++)
                {
                    if((num[k][j]&&(i&(1<<(k - 1))))||(!num[k][j]&&!(i&(1<<(k - 1)))))
                        res1++;
                    else
                        res2++;
                }
                res += min(res1, res2);
            }
            ans = min(ans, res);
        }
    }
    if(ans > k)
        printf("-1\n");
    else
        printf("%d\n", ans);
    return 0;
}


#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define N 10010
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define ist insert
#define ers erase
#define ft first
#define sd second
#define bs bitset
#define len(x) (x).length()
#define st system("pause")
#define pii pair<int,int>
#define ppi pair<pii,pii>
#define pll pair<ll,ll>
#define pss pair<string,string>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define vl vector<ll>
#define vvl vector<vl>
#define vstr vector<string>
#define vc vector<char>
#define SQR(x) ((x)*(x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define Size(v) (int)v.size()
#define SorT(v) sort(ALL(v))
#define ReversE(v) reverse(ALL(v))
#define Sort(arr,sz) sort(ALLA(arr,sz))
#define Reverse(arr,sz) reverse(ALLA(arr,sz))
#define Permute next_permutation
#define TC(t) while(t--)
using namespace std;
double EPS=1e-9;
int INF =2000000000;
long long LINF=8000000000000000000LL;
const ll MOD=1000000007LL;
double PI=acos(-1);
int dirx[8]={-1,0,0,1,-1,-1,1,1};
int diry[8]={0,1,-1,0,-1,1,-1,1};
inline ll gcd(ll x,ll y)
{
	if(y==0)return x;else return gcd(y,x%y);
}
inline ll lcm(ll x,ll y)
{
	return x*y/gcd(x,y);
}
inline string itos(int a)
{
    char x[100];
    sprintf(x,"%d",a);
    string s=x;
    return s;
}
inline int stoi(string a)
{
    char x[100];
    int res;
    strcpy(x,a.c_str());
    sscanf(x,"%d",&res);
    return res;
}
inline string uppercs(string s)
{
    int n=Size(s);
    for(int i=0;i<n;i++)if(s[i]>='a' && s[i]<='z')s[i]=s[i]-'a'+'A';
    return s;
}
inline string lowercs(string s)
{
    int n=Size(s);
    for(int i=0;i<n;i++)if(s[i]>='A' && s[i]<='Z')s[i]=s[i]-'A'+'a';
    return s;
}
inline void OPEN(string s)
{
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdin);
}
//end of the kkglove's template v2.0.2 (ALPHA)
bool a[110][110];
int n,m,k,all;
int main()
{
	cin>>n>>m>>k;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>a[i][j];
		}
	}
	all=m*n;
	if(k<n)
	{
		for(int i=0;i<=k;i++)
		{
			int r=0;
			for(int j=0;j<n;j++)
			{
				int ro=0;
				for(int ii=0;ii<m;ii++)
				{
					ro+=a[i][ii]^a[j][ii];
				}
    			r+=min(ro,m-ro);
			}
			all=min(all,r);
		}
	}
	else
	{
		for(int i=0;i<1<<n;i++)
		{
			int r=0;
			for(int j=0;j<m;j++)
			{
				int c=0;
				for(int ii=0;ii<n;ii++)
				{
					c+=(i>>ii&1)^a[i][j];
				}
				r+=min(c,n-c);
			}
			all=min(all,r);
		}
	}
	if(all<=k)cout<<all<<endl;else cout<<-1<<endl;
    return 0;
}


#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define N 10010
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define ist insert
#define ers erase
#define ft first
#define sd second
#define bs bitset
#define len(x) (x).length()
#define st system("pause")
#define pii pair<int,int>
#define ppi pair<pii,pii>
#define pll pair<ll,ll>
#define pss pair<string,string>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define vl vector<ll>
#define vvl vector<vl>
#define vstr vector<string>
#define vc vector<char>
#define SQR(x) ((x)*(x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define Size(v) (int)v.size()
#define SorT(v) sort(ALL(v))
#define ReversE(v) reverse(ALL(v))
#define Sort(arr,sz) sort(ALLA(arr,sz))
#define Reverse(arr,sz) reverse(ALLA(arr,sz))
#define Permute next_permutation
#define TC(t) while(t--)
using namespace std;
double EPS=1e-9;
int INF =2000000000;
long long LINF=8000000000000000000LL;
const ll MOD=1000000007LL;
double PI=acos(-1);
int dirx[8]={-1,0,0,1,-1,-1,1,1};
int diry[8]={0,1,-1,0,-1,1,-1,1};
inline ll gcd(ll x,ll y)
{
	if(y==0)return x;else return gcd(y,x%y);
}
inline ll lcm(ll x,ll y)
{
	return x*y/gcd(x,y);
}
inline string itos(int a)
{
    char x[100];
    sprintf(x,"%d",a);
    string s=x;
    return s;
}
inline int stoi(string a)
{
    char x[100];
    int res;
    strcpy(x,a.c_str());
    sscanf(x,"%d",&res);
    return res;
}
inline string uppercs(string s)
{
    int n=Size(s);
    for(int i=0;i<n;i++)if(s[i]>='a' && s[i]<='z')s[i]=s[i]-'a'+'A';
    return s;
}
inline string lowercs(string s)
{
    int n=Size(s);
    for(int i=0;i<n;i++)if(s[i]>='A' && s[i]<='Z')s[i]=s[i]-'A'+'a';
    return s;
}
inline void OPEN(string s)
{
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdin);
}
//end of the kkglove's template v2.0.2 (ALPHA)
bool a[110][110];
int n,m,k,all;
int main()
{
	cin>>m>>n>>k;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	all=m*n;
	if(k<m)
	{
		for(int pi=0;pi<=k;pi++)
		{
			int co=0;
			for(int i=0;i<m;i++)
			{
				int r=0;
				for(int j=0;j<n;j++)
				{
					r+=a[pi][j]^a[i][j];
				}
    			co+=min(r,n-r);
			}
			all=min(all,co);
		}
	}
	else
	{
		for(int mk=0;mk<1<<m;mk++)
		{
			int co=0;
			for(int j=0;j<n;j++)
			{
				int c=0;
				for(int i=0;i<m;i++)
				{
					c+=(mk>>i&1)^a[i][j];
				}
				co+=min(c,m-c);
			}
			all=min(all,co);
		}
	}
	if(all<=k)cout<<all<<endl;else cout<<-1<<endl;
    return 0;
}


#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define ist insert
#define ers erase
#define ft first
#define sd second
#define bs bitset
#define len(x) (x).length()
#define st system("pause")
#define pii pair<int,int>
#define ppi pair<pii,pii>
#define pll pair<ll,ll>
#define pss pair<string,string>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define vl vector<ll>
#define vvl vector<vl>
#define vstr vector<string>
#define vc vector<char>
#define SQR(x) ((x)*(x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define Size(v) (int)v.size()
#define SorT(v) sort(ALL(v))
#define ReversE(v) reverse(ALL(v))
#define Sort(arr,sz) sort(ALLA(arr,sz))
#define Reverse(arr,sz) reverse(ALLA(arr,sz))
#define Permute next_permutation
#define TC(t) while(t--)
using namespace std;
double EPS=1e-9;
int INF =2000000000;
long long LINF=8000000000000000000LL;
const ll MOD=1000000007LL;
double PI=acos(-1);
int dirx[8]={-1,0,0,1,-1,-1,1,1};
int diry[8]={0,1,-1,0,-1,1,-1,1};
inline ll gcd(ll x,ll y)
{
	if(y==0)return x;else return gcd(y,x%y);
}
inline ll lcm(ll x,ll y)
{
	return x*y/gcd(x,y);
}
inline string itos(int a)
{
    char x[100];
    sprintf(x,"%d",a);
    string s=x;
    return s;
}
inline int stoi(string a)
{
    char x[100];
    int res;
    strcpy(x,a.c_str());
    sscanf(x,"%d",&res);
    return res;
}
inline string uppercs(string s)
{
    int n=Size(s);
    for(int i=0;i<n;i++)if(s[i]>='a' && s[i]<='z')s[i]=s[i]-'a'+'A';
    return s;
}
inline string lowercs(string s)
{
    int n=Size(s);
    for(int i=0;i<n;i++)if(s[i]>='A' && s[i]<='Z')s[i]=s[i]-'A'+'a';
    return s;
}
inline void OPEN(string s)
{
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdin);
}
//end of the kkglove's template v2.0.2 (ALPHA)
bool a[110][110];
int n,m,k,all;
int main()
{
	cin>>m>>n>>k;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	all=m*n;
	if(k<m)
	{
		for(int pi=0;pi<=k;pi++)
		{
			int co=0;
			for(int i=0;i<m;i++)
			{
				int r=0;
				for(int j=0;j<n;j++)
				{
					r+=a[pi][j]^a[i][j];
				}
    			co+=min(r,n-r);
			}
			all=min(all,co);
		}
	}
	else
	{
		for(int mk=0;mk<1<<m;mk++)
		{
			int co=0;
			for(int j=0;j<n;j++)
			{
				int c=0;
				for(int i=0;i<m;i++)
				{
					c+=(mk>>i&1)^a[i][j];
				}
				co+=min(c,m-c);
			}
			all=min(all,co);
		}
	}
	if(all<=k)cout<<all<<endl;else cout<<-1<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define cout2(x, y) cout<<x<<" "<<y<<endl;
#define MAXN 102

using namespace std;

int T[MAXN][MAXN], n, m;

int eval(int mask, int col){

    int ans1 = 0, ans2 = 0;

    for(int i = 0; i < n; i++)ans1 += (((mask>>i)&1)^T[i][col]);
    for(int i = 0; i < n; i++)ans2 += (((mask>>i)&1)^(1 - T[i][col]));

    return min(ans1, ans2);
}

int naive(){

    int ans = (1<<30);

    for(int i = 0; i < (1<<n); i++){
        int val = 0;
        for(int j = 0; j < m; j++)val += eval(i, j);
        ans = min(ans, val);
    }

    return ans;

}

int dist(int fil1, int fil2){

    int ans1 = 0, ans2 = 0;
    for(int j = 0; j < m; j++)ans1 += (T[fil1][j]^T[fil2][j]);
    for(int j = 0; j < m; j++)ans2 += ((1 - T[fil1][j])^T[fil2][j]);
    return min(ans1, ans2);

}

int solve(){

    int ans = (1<<30);

    for(int i = 0; i < n; i++){
        int val = 0;
        for(int k = 0; k < n; k++)val += dist(i, k);
        ans = min(ans, val);
    }

    return ans;

}

int main() {

    int k;
    while(cin>>n>>m>>k){

        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)cin>>T[i][j];

        int ans;

        if(n <= 10)ans = naive();
        else ans = solve();

        if(ans <= k)printf("%d\n", ans);
        else puts("-1");

    }

}


#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define FF(i, a, b) for(int i = a; i <= b; i++)
#define abs(x) ((x) > 0 ? (x) : -(x))
#define O 128
#define N 51
#define inf 0x3f3f3f3f
#define lowbit(x) ((x) & (-x))
#define eps 1e-8
using namespace std;
typedef unsigned long long LL;
const LL MOD = 1e9 + 7;
int read(){
    char ch = ' ';
    while(ch < '0' || ch > '9') ch = getchar();
    int x = 0;
    while(ch >= '0' && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x;
}

int n,m,k,ans1, ans2;
int a[105][105];
int d[3][105];
int a1[105];

int main(){
    scanf("%d %d %d",&n,&m,&k);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
        scanf("%d",&a[i][j]);
    }
    ans1=2140000000, ans2=2140000000;
    for(int i=1;i<=n;i++){
        int an=0;
        for(int j=1;j<=n;j++){
            int op=0;
            for(int k=1;k<=m;k++) if(a[i][k]!=a[j][k]) op++;
            an+=min(op,m-op);
        }
        ans1=min(ans1,an);
    }
    for(int i=1;i<=m;i++){
        int an=0;
        for(int j=1;j<=m;j++){
            int op=0;
            for(int k=1;k<=n;k++) if(a[i][k]!=a[j][k]) op++;
            an+=min(op,n-op);
        }
        ans2=min(ans2,an);
    }
    if(ans1>k && ans2 > k) printf("-1");
    else printf("%d",ans1 < ans2 ? ans1 : ans2);
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define FF(i, a, b) for(int i = a; i <= b; i++)
#define abs(x) ((x) > 0 ? (x) : -(x))
#define O 128
#define N 51
#define inf 0x3f3f3f3f
#define lowbit(x) ((x) & (-x))
#define eps 1e-8
using namespace std;
typedef unsigned long long LL;
const LL MOD = 1e9 + 7;
int read(){
    char ch = ' ';
    while(ch < '0' || ch > '9') ch = getchar();
    int x = 0;
    while(ch >= '0' && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x;
}

int n,m,k,ans;
int a[105][105];
int d[3][105];
int a1[105];

int main(){
    scanf("%d %d %d",&n,&m,&k);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
        scanf("%d",&a[i][j]);
    }
    ans=2140000000;
    if(n>11){
        for(int i=1;i<=n;i++){
            int an=0;
            for(int j=1;j<=n;j++){
                int op=0;
                for(int k=1;k<=m;k++) if(a[i][k]!=a[j][k]) op++;
                an+=min(op,m-op);
            }
            ans=min(ans,an);
        }
    }
    else{
        for(int i=0;i<(1<<n);i++){
            for(int j=0;j<n;j++){
                if((i&(1<<j))!=0) a1[j]=1;
                else a1[j]=0;
            }
            int an=0;
            for(int j=1;j<=m;j++){
                int op=0;
                for(int k=1;k<=n;k++) if(a[k][j]!=a1[k-1]) op++;
                an+=min(op,n-op);
            }
            ans=min(ans,an);
        }
    }
    if(ans>k) printf("-1");
    else printf("%d",ans);
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define FF(i, a, b) for(int i = a; i <= b; i++)
#define abs(x) ((x) > 0 ? (x) : -(x))
#define O 128
#define N 51
#define inf 0x3f3f3f3f
#define lowbit(x) ((x) & (-x))
#define eps 1e-8
using namespace std;
typedef unsigned long long LL;
const LL MOD = 1e9 + 7;
int read(){
    char ch = ' ';
    while(ch < '0' || ch > '9') ch = getchar();
    int x = 0;
    while(ch >= '0' && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x;
}
int main(){
    int ok = 0, a[O] = {0}, b[O], n = read(), m = read(), k = read(), min = inf;
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) a[i] += read();
    for(int i = 0; i < n; i++){
        int sum = 0;
        for(int j = i - 1; j >= 0; j--) sum += abs(a[i] - a[j]);
        for(int j = i + 1; j <  n; j++) sum += abs(a[i] - a[j]);
        if(sum <= k){
            ok = 1;
            if(min > sum) min = sum;
        }

    }
    printf(ok ? "%d\n" : "-1\n", min);
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define FF(i, a, b) for(int i = a; i <= b; i++)
#define abs(x) ((x) > 0 ? (x) : -(x))
#define O 128
#define N 51
#define inf 0x3f3f3f3f
#define lowbit(x) ((x) & (-x))
#define eps 1e-8
using namespace std;
typedef unsigned long long LL;
const LL MOD = 1e9 + 7;
int read(){
    char ch = ' ';
    while(ch < '0' || ch > '9') ch = getchar();
    int x = 0;
    while(ch >= '0' && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x;
}

int n,m,k,ans;
int a[105][105];
int d[3][105];
int a1[105];

int main(){
    scanf("%d %d %d",&n,&m,&k);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
        scanf("%d",&a[i][j]);
    }
    ans=2140000000;
    if(n>2){
        for(int i=1;i<=n;i++){
            int an=0;
            for(int j=1;j<=n;j++){
                int op=0;
                for(int k=1;k<=m;k++) if(a[i][k]!=a[j][k]) op++;
                an+=min(op,m-op);
            }
            ans=min(ans,an);
        }
    }
    else{
        for(int i=0;i<(1<<n);i++){
            for(int j=0;j<n;j++){
                if((i&(1<<j))!=0) a1[j]=1;
                else a1[j]=0;
            }
            int an=0;
            for(int j=1;j<=m;j++){
                int op=0;
                for(int k=1;k<=n;k++) if(a[k][j]!=a1[k-1]) op++;
                an+=min(op,n-op);
            }
            ans=min(ans,an);
        }
    }
    if(ans>k) printf("-1");
    else printf("%d",ans);
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define FF(i, a, b) for(int i = a; i <= b; i++)
#define abs(x) ((x) > 0 ? (x) : -(x))
#define O 128
#define N 51
#define inf 0x3f3f3f3f
#define lowbit(x) ((x) & (-x))
#define eps 1e-8
using namespace std;
typedef unsigned long long LL;
const LL MOD = 1e9 + 7;
int read(){
    char ch = ' ';
    while(ch < '0' || ch > '9') ch = getchar();
    int x = 0;
    while(ch >= '0' && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x;
}

int n,m,k,ans;
int a[105][105];
int d[3][105];
int a1[105];

int main(){
    scanf("%d %d %d",&n,&m,&k);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
        scanf("%d",&a[i][j]);
    }
    ans=2140000000;
    if(n>10){
        for(int i=1;i<=n;i++){
            int an=0;
            for(int j=1;j<=n;j++){
                int op=0;
                for(int k=1;k<=m;k++) if(a[i][k]!=a[j][k]) op++;
                an+=min(op,m-op);
            }
            ans=min(ans,an);
        }
    }
    else{
        for(int i=0;i<(1<<n);i++){
            for(int j=0;j<n;j++){
                if((i&(1<<j))!=0) a1[j]=1;
                else a1[j]=0;
            }
            int an=0;
            for(int j=1;j<=m;j++){
                int op=0;
                for(int k=1;k<=n;k++) if(a[k][j]!=a1[k-1]) op++;
                an+=min(op,n-op);
            }
            ans=min(ans,an);
        }
    }
    if(ans>k) printf("-1");
    else printf("%d",ans);
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define FF(i, a, b) for(int i = a; i <= b; i++)
#define abs(x) ((x) > 0 ? (x) : -(x))
#define O 128
#define N 51
#define inf 0x3f3f3f3f
#define lowbit(x) ((x) & (-x))
#define eps 1e-8
using namespace std;
typedef unsigned long long LL;
const LL MOD = 1e9 + 7;
int read(){
    char ch = ' ';
    while(ch < '0' || ch > '9') ch = getchar();
    int x = 0;
    while(ch >= '0' && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x;
}

int n,m,k,ans;
int a[105][105];
int d[3][105];
int a1[105];

int main(){
    scanf("%d %d %d",&n,&m,&k);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
        scanf("%d",&a[i][j]);
    }
    ans=2140000000;
    for(int i=1;i<=n;i++){
        int an=0;
        for(int j=1;j<=n;j++){
            int op=0;
            for(int k=1;k<=m;k++) if(a[i][k]!=a[j][k]) op++;
            an+=min(op,m-op);
        }
        ans=min(ans,an);
    }
    if(ans>k) printf("-1");
    else printf("%d",ans);
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

class Solution
{
public:
int MinChange(int a[][100], int n, int m, int k)
{
	if (n <= k)
	{
		int ans = 1e9;
		for (int t = 0; t < (1<<k); t++)
		{
			int sum = 0;
			for (int i = 0; i < m; i++)
			{
				int bit = 0;
				for (int j = 0; j < n; j++) bit += (1 << a[j][i]);
				sum += min(BitNum(t ^ bit), BitNum(t ^ ((1<<k) - 1 - bit)));
			}
			ans = min(sum, ans);
		}
		if (ans > k) return -1; else return ans;
	}
	int ans = 1e9;
	for (int i = 0; i < n; i++)
	{
		int sum = 0;
		for (int j = 0; j < n; j++)
		if (i != j)
{
			int f0 = 0, f1 = 0;
			if (a[j][0] == 0) f1++; else f0++;
			for (int k = 1; k < m; k++)
			if (a[i][0] == a[i][k])
			{
				if (a[j][k] == 0) f1++; else f0++;
			} else
			{
				if (a[j][k] == 0) f0++; else f1++;
			}
			sum += min(f0, f1);
		}
		ans = min(ans, sum);
	}
	if (ans > k) return -1; return ans;
}

private:
int BitNum(int num)
{
	int ans = 0;
	while (num)
	{
		ans += (num & 1);
		num >>= 1;
	}
	return ans;
}
};

int a[100][100];
int main()
{
	int n, m, k;scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
	Solution ans;
	printf("%d\n", ans.MinChange(a, n, m, k));
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

class Solution
{
public:
int MinChange(int a[][100], int n, int m, int k)
{
	if (n <= k)
	{
		int ans = 1e9;
		for (int t = 0; t < (1<<k); t++)
		{
			int sum = 0;
			for (int i = 0; i < m; i++)
			{
				int bit = 0;
				for (int j = 0; j < n; j++) bit += (1 << (j * a[j][i]));
				sum += min(BitNum(t ^ bit), BitNum(t ^ ((1<<k) - 1 - bit)));
			}
			ans = min(sum, ans);
		}
		if (ans > k) return -1; else return ans;
	}
	int ans = 1e9;
	for (int i = 0; i < n; i++)
	{
		int sum = 0;
		for (int j = 0; j < n; j++)
		if (i != j)
{
			int f0 = 0, f1 = 0;
			if (a[j][0] == 0) f1++; else f0++;
			for (int k = 1; k < m; k++)
			if (a[i][0] == a[i][k])
			{
				if (a[j][k] == 0) f1++; else f0++;
			} else
			{
				if (a[j][k] == 0) f0++; else f1++;
			}
			sum += min(f0, f1);
		}
		ans = min(ans, sum);
	}
	if (ans > k) return -1; return ans;
}

private:
int BitNum(int num)
{
	int ans = 0;
	while (num)
	{
		ans += (num & 1);
		num >>= 1;
	}
	return ans;
}
};

int a[100][100];
int main()
{
	int n, m, k;scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
	Solution ans;
	printf("%d\n", ans.MinChange(a, n, m, k));
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

class Solution
{
public:
int MinChange(int a[][100], int n, int m, int k)
{
	if (n <= k)
	{
		int ans = 1e9;
		for (int t = 0; t < (1<<k); t++)
		{
			int sum = 0;
			for (int i = 0; i < m; i++)
			{
				int bit = 0;
				for (int j = 0; j < n; j++) bit += (1 << a[j][i]);
				sum += min(BitNum(t ^ bit), BitNum(t ^ ((1<<k) - 1 - bit)));
			}
			ans = min(sum, ans);
		}
		if (ans > k) return -1; else reuen ans;
	}
	int change[n][2];
	memset(change, 0, sizeof(change));
	for (int j = 1; j < m; j++)
	{
		int same = 0, diff = 0;
		for (int i = 0; i < n; i++) if (a[i][j] == a[i][0]) same++; else diff++;
		if (same > diff)
		{
			for (int i = 0; i < n; i++)
			{
				if (a[i][j] == 1) change[i][0]++;
				else change[i][1]++;
			}
		} else
{
			for (int i = 0; i < n; i++)
			{
				if (a[i][j] == 0) change[i][0]++;
				else change[i][1]++;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) ans += min(change[i][0] + (a[i][0] == 0), change[i][1] + (a[i][0] == 1));
	if (ans > k) return -1; return ans;
}

private:
int BitNum(int num)
{
	int ans = 0;
	while (num)
	{
		ans += (num & 1);
		num >>= 1;
	}
	return ans;
}
};

int a[100][100];
int main()
{
	int n, m, k;scanf(“%d%d%d”, &n, &m, &k);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) scanf(“%d”, &a[i][j]):
	Solution ans;
	printf(“%d\n”, ans.MinChange(a, n, m, k));
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

class Solution
{
public:
int MinChange(int a[][100], int n, int m, int k)
{
	if (n <= k)
	{
		int ans = 1e9;
		for (int t = 0; t < (1<<k); t++)
		{
			int sum = 0;
			for (int i = 0; i < m; i++)
			{
				int bit = 0;
				for (int j = 0; j < n; j++) bit += (a[j][i] << j);
				sum += min(BitNum(t ^ bit), BitNum(t ^ ((1<<k) - 1 - bit)));
			}
			ans = min(sum, ans);
		}
		if (ans > k) return -1; else return ans;
	}
	int ans = 1e9;
	for (int i = 0; i < n; i++)
	{
		int sum = 0;
		for (int j = 0; j < n; j++)
		if (i != j)
{
			int f0 = 0, f1 = 0;
			if (a[j][0] == 0) f1++; else f0++;
			for (int k = 1; k < m; k++)
			if (a[i][0] == a[i][k])
			{
				if (a[j][k] == 0) f1++; else f0++;
			} else
			{
				if (a[j][k] == 0) f0++; else f1++;
			}
			sum += min(f0, f1);
		}
		ans = min(ans, sum);
	}
	if (ans > k) return -1; return ans;
}

private:
int BitNum(int num)
{
	int ans = 0;
	while (num)
	{
		ans += (num & 1);
		num >>= 1;
	}
	return ans;
}
};

int a[100][100];
int main()
{
	int n, m, k;scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
	Solution ans;
	printf("%d\n", ans.MinChange(a, n, m, k));
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
class Solution
{
public:
int MinChange(int a[][100], int n, int m, int k)
{
	if (n <= k)
	{
		int ans = 1e9;
		for (int t = 0; t < (1<<k); t++)
		{
			int sum = 0;
			for (int i = 0; i < m; i++)
			{
				int bit = 0;
				for (int j = 0; j < n; j++) bit += (1 << (j * a[j][i]));
				sum += min(BitNum(t ^ bit), BitNum(t ^ ((1<<k) - 1 - bit)));
			}
			ans = min(sum, ans);
		}
		if (ans > k) return -1; else return ans;
	}
	int ans = 1e9;
	for (int i = 0; i < n; i++)
	{
		int sum = 0;
		for (int j = 0; j < n; j++)
		if (i != j)
{
			int f0 = 0, f1 = 0;
			if (a[j][0] == 0) f1++; else f0++;
			for (int k = 1; k < m; k++)
			if (a[i][0] == a[i][k])
			{
				if (a[j][k] == 0) f1++; else f0++;
			} else
			{
				if (a[j][k] == 0) f0++; else f1++;
			}
			sum += min(f0, f1);
		}
		ans = min(ans, sum);
	}
	if (ans > k) return -1; return ans;
}

private:
int BitNum(int num)
{
	int ans = 0;
	while (num)
	{
		ans += (num & 1);
		num >>= 1;
	}
	return ans;
}
};

int a[100][100];
int main()
{
	int n, m, k;scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
	Solution ans;
	printf("%d\n", ans.MinChange(a, n, m, k));
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

class Solution
{
public:
int MinChange(int a[][100], int n, int m, int k)
{
	if (n <= k)
	{
		int ans = 1e9;
		for (int t = 0; t < (1<<n); t++)
		{
			int sum = 0;
			for (int i = 0; i < m; i++)
			{
				int bit = 0;
				for (int j = 0; j < n; j++) bit += (a[j][i] << j);
				sum += min(BitNum(t ^ bit), BitNum(t ^ ((1<<n) - 1 - bit)));
			}
			ans = min(sum, ans);
		}
		if (ans > k) return -1; else return ans;
	}
	int ans = 1e9;
	for (int i = 0; i < n; i++)
	{
		int sum = 0;
		for (int j = 0; j < n; j++)
		if (i != j)
{
			int f0 = 0, f1 = 0;
			if (a[j][0] == 0) f1++; else f0++;
			for (int k = 1; k < m; k++)
			if (a[i][0] == a[i][k])
			{
				if (a[j][k] == 0) f1++; else f0++;
			} else
			{
				if (a[j][k] == 0) f0++; else f1++;
			}
			sum += min(f0, f1);
		}
		ans = min(ans, sum);
	}
	if (ans > k) return -1; return ans;
}

private:
int BitNum(int num)
{
	int ans = 0;
	while (num)
	{
		ans += (num & 1);
		num >>= 1;
	}
	return ans;
}
};

int a[100][100];
int main()
{
	int n, m, k;scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
	Solution ans;
	printf("%d\n", ans.MinChange(a, n, m, k));
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

class Solution
{
public:
int MinChange(int a[][100], int n, int m, int k)
{
	if (n <= k)
	{
		int ans = 1e9;
		for (int t = 0; t < (1<<k); t++)
		{
			int sum = 0;
			for (int i = 0; i < m; i++)
			{
				int bit = 0;
				for (int j = 0; j < n; j++) bit += (1 << a[j][i]);
				sum += min(BitNum(t ^ bit), BitNum(t ^ ((1<<k) - 1 - bit)));
			}
			ans = min(sum, ans);
		}
		if (ans > k) return -1; else reuen ans;
	}
	int change[n][2];
	memset(change, 0, sizeof(change));
	for (int j = 1; j < m; j++)
	{
		int same = 0, diff = 0;
		for (int i = 0; i < n; i++) if (a[i][j] == a[i][0]) same++; else diff++;
		if (same > diff)
		{
			for (int i = 0; i < n; i++)
			{
				if (a[i][j] == 1) change[i][0]++;
				else change[i][1]++;
			}
		} else
{
			for (int i = 0; i < n; i++)
			{
				if (a[i][j] == 0) change[i][0]++;
				else change[i][1]++;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) ans += min(change[i][0] + (a[i][0] == 0), change[i][1] + (a[i][0] == 1));
	if (ans > k) return -1; return ans;
}

private:
int BitNum(int num)
{
	int ans = 0;
	while (num)
	{
		ans += (num & 1);
		num >>= 1;
	}
	return ans;
}
};

int a[100][100];
int main()
{
	int n, m, k;scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) scanf("%d", &a[i][j]):
	Solution ans;
	printf("%d\n", ans.MinChange(a, n, m, k));
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

class Solution
{
public:
int MinChange(int a[][100], int n, int m, int k)
{
	if (n <= k)
	{
		int ans = 1e9;
		for (int t = 0; t < (1<<k); t++)
		{
			int sum = 0;
			for (int i = 0; i < m; i++)
			{
				int bit = 0;
				for (int j = 0; j < n; j++) bit += (1 << a[j][i]);
				sum += min(BitNum(t ^ bit), BitNum(t ^ ((1<<k) - 1 - bit)));
			}
			ans = min(sum, ans);
		}
		if (ans > k) return -1; else return ans;
	}
	int change[n][2];
	memset(change, 0, sizeof(change));
	for (int j = 1; j < m; j++)
	{
		int same = 0, diff = 0;
		for (int i = 0; i < n; i++) if (a[i][j] == a[i][0]) same++; else diff++;
		if (same > diff)
		{
			for (int i = 0; i < n; i++)
			{
				if (a[i][j] == 1) change[i][0]++;
				else change[i][1]++;
			}
		} else
{
			for (int i = 0; i < n; i++)
			{
				if (a[i][j] == 0) change[i][0]++;
				else change[i][1]++;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) ans += min(change[i][0] + (a[i][0] == 0), change[i][1] + (a[i][0] == 1));
	if (ans > k) return -1; return ans;
}

private:
int BitNum(int num)
{
	int ans = 0;
	while (num)
	{
		ans += (num & 1);
		num >>= 1;
	}
	return ans;
}
};

int a[100][100];
int main()
{
	int n, m, k;scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
	Solution ans;
	printf("%d\n", ans.MinChange(a, n, m, k));
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

class Solution
{
public:
int MinChange(int a[][100], int n, int m, int k)
{
	if (n <= k)
	{
		int ans = 1e9;
		for (int t = 0; t < (1<<k); t++)
		{
			int sum = 0;
			for (int i = 0; i < m; i++)
			{
				int bit = 0;
				for (int j = 0; j < n; j++) bit += (1 << a[j][i]);
				sum += min(BitNum(t ^ bit), BitNum(t ^ ((1<<k) - 1 - bit)));
			}
			ans = min(sum, ans);
		}
		if (ans > k) return -1; else return ans;
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		int sum = 0;
		for (int j = 0; j < n; j++)
		if (i != j)
{
			int f0 = 0, f1 = 0;
			if (a[j][0] == 0) f1++; else f0++;
			for (int k = 1; k < m; k++)
			if (a[i][0] == a[i][k])
			{
				if (a[j][k] == 0) f1++; else f0++;
			} else
			{
				if (a[j][k] == 0) f0++; else f1++;
			}
			sum += min(f0, f1);
		}
		ans = min(ans, sum);
	}
	if (ans > k) return -1; return ans;
}

private:
int BitNum(int num)
{
	int ans = 0;
	while (num)
	{
		ans += (num & 1);
		num >>= 1;
	}
	return ans;
}
};

int a[100][100];
int main()
{
	int n, m, k;scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
	Solution ans;
	printf("%d\n", ans.MinChange(a, n, m, k));
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

class Solution
{
public:
int MinChange(int a[][100], int n, int m, int k)
{
	if (n <= k)
	{
		int ans = 1e9;
		for (int t = 0; t < (1<<n); t++)
		{
			int sum = 0;
			for (int i = 0; i < m; i++)
			{
				int bit = 0;
				for (int j = 0; j < n; j++) bit += (a[j][i] << j);
				sum += min(BitNum(t ^ bit), BitNum(t ^ ((1<<k) - 1 - bit)));
			}
			ans = min(sum, ans);
		}
		if (ans > k) return -1; else return ans;
	}
	int ans = 1e9;
	for (int i = 0; i < n; i++)
	{
		int sum = 0;
		for (int j = 0; j < n; j++)
		if (i != j)
{
			int f0 = 0, f1 = 0;
			if (a[j][0] == 0) f1++; else f0++;
			for (int k = 1; k < m; k++)
			if (a[i][0] == a[i][k])
			{
				if (a[j][k] == 0) f1++; else f0++;
			} else
			{
				if (a[j][k] == 0) f0++; else f1++;
			}
			sum += min(f0, f1);
		}
		ans = min(ans, sum);
	}
	if (ans > k) return -1; return ans;
}

private:
int BitNum(int num)
{
	int ans = 0;
	while (num)
	{
		ans += (num & 1);
		num >>= 1;
	}
	return ans;
}
};

int a[100][100];
int main()
{
	int n, m, k;scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
	Solution ans;
	printf("%d\n", ans.MinChange(a, n, m, k));
	return 0;
}


#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define ist insert
#define ers erase
#define ft first
#define sd second
#define bs bitset
#define len(x) (x).length()
#define st system("pause")
#define pii pair<int,int>
#define ppi pair<pii,pii>
#define pll pair<ll,ll>
#define pss pair<string,string>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define vl vector<ll>
#define vvl vector<vl>
#define vstr vector<string>
#define vc vector<char>
#define SQR(x) ((x)*(x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define Size(v) (int)v.size()
#define SorT(v) sort(ALL(v))
#define ReversE(v) reverse(ALL(v))
#define Sort(arr,sz) sort(ALLA(arr,sz))
#define Reverse(arr,sz) reverse(ALLA(arr,sz))
#define Permute next_permutation
#define TC(t) while(t--)
using namespace std;
double EPS=1e-9;
int INF =2000000000;
long long LINF=8000000000000000000LL;
const ll MOD=1000000007LL;
double PI=acos(-1);
int dirx[8]={-1,0,0,1,-1,-1,1,1};
int diry[8]={0,1,-1,0,-1,1,-1,1};
inline ll gcd(ll x,ll y)
{
	if(y==0)return x;else return gcd(y,x%y);
}
inline ll lcm(ll x,ll y)
{
	return x*y/gcd(x,y);
}
inline string itos(int a)
{
    char x[100];
    sprintf(x,"%d",a);
    string s=x;
    return s;
}
inline int stoi(string a)
{
    char x[100];
    int res;
    strcpy(x,a.c_str());
    sscanf(x,"%d",&res);
    return res;
}
inline string uppercs(string s)
{
    int n=Size(s);
    for(int i=0;i<n;i++)if(s[i]>='a' && s[i]<='z')s[i]=s[i]-'a'+'A';
    return s;
}
inline string lowercs(string s)
{
    int n=Size(s);
    for(int i=0;i<n;i++)if(s[i]>='A' && s[i]<='Z')s[i]=s[i]-'A'+'a';
    return s;
}
inline void OPEN(string s)
{
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdin);
}
//end of the kkglove's template v2.0.2 (ALPHA)
bool a[110][110];
int n,m,k,all;
int main()
{
	cin>>m>>n>>k;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	all=m*n;
	if(k<m)
	{
		for(int pi=0;pi<=k;pi++)
		{
			int co=0;
			for(int i=0;i<m;i++)
			{
				int r=0;
				for(int j=0;j<n;j++)
				{
					r+=a[pi][j]^a[i][j];
				}
    			co+=min(r,n-r);
			}
			all=min(all,co);
		}
	}
	else
	{
		for(int mk=0;mk<1<<m;mk++)
		{
			int co=0;
			for(int j=0;j<n;j++)
			{
				int c=0;
				for(int i=0;i<m;i++)
				{
					c+=(mk>>i&1)^a[i][j];
				}
				co+=min(c,m-c);
			}
			all=min(all,co);
		}
	}
	if(all<=k)cout<<all<<endl;else cout<<-1<<endl;
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<stack>

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

#define tr(x) cout<<x<<endl;
#define tr2(x,y) cout<<x<<" "<<y<<endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(w,x,y,z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl;

using namespace std;

int n, m, k;
int a[100][100], mn = 1000;

int calc(int row){
	int c1 = 0, c2 = 0, tot = 0;
	for(int i = 0; i < n; i++){
		c1 = c2 = 0;
		for(int j = 0; j < m; j++){
			if(a[row][j] == a[i][j]) c1++; else c2++;
		}
		if(c1 == m or c2 == m) continue;

		tot += m - max(c1,c2);
	}
	return tot;
}

int main(){
	sd3(n,m,k);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			sd(a[i][j]);
		}
	}

	for(int i = 0; i < n; i++){
		mn = min(mn, calc(i));
	}

	if(mn <= k) cout << mn << "\n";
	else cout << -1 << "\n";
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<stack>

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

#define tr(x) cout<<x<<endl;
#define tr2(x,y) cout<<x<<" "<<y<<endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(w,x,y,z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl;

using namespace std;

int n, m, k;
int a[100][100], b[100], mn = 1000;

int calc(int row){
	int c1 = 0, c2 = 0, tot = 0;
	for(int i = 0; i < n; i++){
		c1 = c2 = 0;
		for(int j = 0; j < m; j++){
			if(a[row][j] == a[i][j]) c1++; else c2++;
		}
		tot += m - max(c1,c2);
	}
	return tot;
}

int main(){
	sd3(n,m,k);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			sd(a[i][j]);
		}
	}

	if(n > k){
		for(int i = 0; i < n; i++){
			mn = min(mn, calc(i));
		}
	}
	else{
		for(int i = 0; i < (1<<n); i++){
			for(int j = 0; j < n; j++){
				if((i&(1<<j)) > 0){
					b[j] = 1;
				}
				else{
					b[j] = 0;
				}
			}
			int tot = 0;
			for(int j = 0; j < m; j++){
				int c1 = 0, c2 = 0;
				for(int k = 0; k < n; k++){
					if(b[k] == a[k][j]) c1++; else c2++;
				}
				tot += n - max(c1,c2);
			}

			mn = min(mn, tot);
		}
	}

	if(mn <= k) cout << mn << "\n";
	else cout << -1 << "\n";
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <string>
using namespace std;
int a[110][110],b[110];
int main()
{
    int n,m,k;
    while(scanf("%d %d %d",&n,&m,&k) != EOF)
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= m; j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        int ans = 100;
        if(n > k)
        {
            for(int i = 1; i <= n; i++)
            {
                int sum = 0;
                for(int j = 1; j <= n; j++)
                {
                    if(j == i)continue;
                    int x = 0,y = 0;
                    for(int c = 1; c <= m; c++)
                    {
                        if(a[i][c] != a[j][c])x++;
                        if(a[i][c] == a[j][c])y++;
                    }
                    sum += min(x,y);
                    if(sum > k)break;
                }
                if(sum > k)continue;
                if(sum < ans)ans = sum;
            }
            if(ans < 100)printf("%d\n",ans);
            else printf("-1\n");
        }
        else
        {
            int s = 1<<n;
            for(int i = 0; i < s; i++)
            {
                for(int j = 1; j <= n; j++)
                {
                    if(i&(1<<(j-1)))b[j] = 1;
                    else b[j] = 0;
                }
                int sum = 0;
                for(int j = 1; j <= m; j++)
                {
                    int x = 0,y = 0;
                    for(int r = 1; r <= n; r++)
                    {
                        if(a[r][j] != b[r])x++;
                        if(a[r][j] == b[r])y++;
                    }
                    if(j == 1)sum += x;
                    else sum += min(x,y);
                }
                if(sum <= k && sum < ans)
                {
                    ans = sum;
                }
            }
            if(ans < 100)printf("%d\n",ans);
            else printf("-1\n");
        }
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <string>
using namespace std;
int a[110][110],b[110];
int main()
{
    int n,m,k;
    while(scanf("%d %d %d",&n,&m,&k) != EOF)
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= m; j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        int ans = 100;
        if(n > k)
        {
            for(int i = 1; i <= n; i++)
            {
                int sum = 0;
                for(int j = 1; j <= n; j++)
                {
                    if(j == i)continue;
                    int x = 0,y = 0;
                    for(int c = 1; c <= m; c++)
                    {
                        if(a[i][c] != a[j][c])x++;
                        if(a[i][c] == a[j][c])y++;
                    }
                    sum += min(x,y);
                    if(sum > k)break;
                }
                if(sum > k)continue;
                if(sum < ans)ans = sum;
            }
            if(ans < 100)printf("%d\n",ans);
            else printf("-1\n");
        }
        else
        {
            int s = 1<<n;
            for(int i = 0; i < s; i++)
            {
                for(int j = 1; j <= n; j++)
                {
                    if(s&(1<<(j-1)))b[j] = 1;
                    else b[j] = 0;
                }
                int sum = 0;
                for(int j = 1; j <= m; j++)
                {
                    int x = 0,y = 0;
                    for(int r = 1; r <= n; r++)
                    {
                        if(a[r][j] != b[r])x++;
                        if(a[r][j] == b[r])y++;
                    }
                    if(j == 1)sum += x;
                    else sum += min(x,y);
                }
                if(sum <= k && sum < ans)
                {
                    ans = sum;
                }
            }
            if(ans < 100)printf("%d\n",ans);
            else printf("-1\n");
        }
    }
    return 0;
}


#include <cstdio>
using namespace std;
int m,n,k,a[101][101],*t,res;
int main()
{
    scanf("%d %d %d",&m,&n,&k);
    for(int i = 0;i < m;++i)
        for(int j = 0;j < n;++j)
            scanf("%d",&a[i][j]);
    res = 1000000000;
    if(m > k)
    {
        for(int i = 0;i < m;++i)
        {
            t = a[i];
            int rs = 0;
            for(int j = 0;j < m;++j)
            {
                int sum1 = 0,sum2 =0;
                for(int s = 0;s < n;++s)
                {
                    if(a[j][s] == t[s])
                        sum1 += 1;
                    else
                        sum2 += 1;
                }
                rs += (sum1 < sum2)?sum1:sum2;
            }
            res = (res < rs)?res:rs;
            if(res == 0) break;
        }
    }
    else
    {
        t = new int[m];
        for(int num = 0;num < (1<<m);++num)
        {
            for(int i = 0;i < m;++i)
            t[i] = (num>>i)&1;
            int rs = 0;
            for(int j = 0;j < n;++j)
            {
                int sum1 = 0,sum2 = 0;
                for(int s = 0;s < m;++s)
                if(a[s][j] == t[s])
                sum1 ++;
                else
                sum2 ++;
                rs += sum1 < sum2 ? sum1:sum2;
            }
            res = res < rs ? res:rs;
        }
    }
    printf("%d\n",res>k ? -1:res);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=550,mod=1000000007;
long long p[maxn*maxn];
int n,K;
long long dp[maxn][maxn]={0};
int main()
{
	int i,j,k;
	scanf("%d%d",&n,&K);
	for(p[0]=i=1;i<maxn*maxn;i++)
		p[i]=p[i-1]*2%mod;
	for(i=0;i<=n;i++)
	{
		dp[i][0]=1;
		for(j=1;j<=K;j++)
		{
			for(k=1;k<=i;k++)
				dp[i][j]+=(p[k]-1)*p[(i-k)*k]%mod*dp[i-k][j-1]%mod;
			dp[i][j]%=mod;
		}
	}
	printf("%I64d\n",dp[n][K]);
	return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=120;
int n,m,K,A[maxn][maxn];
int dp[maxn][2]={0},ans=0x7fffffff;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
#endif
	int i,j,k;
	scanf("%d%d%d",&n,&m,&K);
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			scanf("%d",&A[i][j]);
	if(n<m)
	{
		int A0[maxn][maxn];
		for(i=0;i<n;i++)
			for(j=0;j<m;j++)
				A0[j][i]=A[i][j];
		swap(n,m);
		for(i=0;i<n;i++)
			for(j=0;j<m;j++)
				A[i][j]=A0[i][j];
	}
	if(m<=10)
	{
		for(i=0;i<(1<<m);i++)
		{
			int ans0=0;
			for(j=0;j<n;j++)
			{
				int s1=0,s2=0;
				for(k=0;k<m;k++)
					if(A[j][k]!=((i>>k)&1)) s1++;
					else s2++;
				//printf("%d %d\n",s1,s2);
				ans0+=min(s1,s2);
			}
			ans=min(ans,ans0);
		}
	}
	else
		for(i=0;i<n;i++)
		{
			int ans0=0;
			for(j=0;j<n;j++)
			{
				int s1=0,s2=0;
				for(k=0;k<m;k++)
					if(A[j][k]!=A[i][k]) s1++;
					else s2++;
				//printf("%d %d\n",s1,s2);
				ans0+=min(s1,s2);
			}
			ans=min(ans,ans0);
		}
	printf("%d\n",ans>K?-1:ans);
	return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=100050;
int n,p[maxn][2],ans=0;
int ord1[maxn],ord2[maxn],d1[maxn],d2[maxn];
int hs=0,he[maxn*50],ne[maxn*50]={0};
long long key[maxn];
bool cmp1(const int &xx,const int &yy) { return p[xx][0]==p[yy][0]?p[xx][1]<p[yy][1]:p[xx][0]<p[yy][0]; }
bool cmp2(const int &xx,const int &yy) { return p[xx][1]==p[yy][1]?p[xx][0]<p[yy][0]:p[xx][1]<p[yy][1]; }
void push(int x,int y)
{
	int i;
	long long hash=x*maxn+y,h0=hash%(maxn*50);
	key[++hs]=hash;
	ne[hs]=he[h0];
	he[h0]=hs;
}
bool judg(int x,int y)
{
	int i;
	long long hash=x*maxn+y,h0=hash%(maxn*50);
	for(i=he[h0];i;i=ne[i])
		if(key[i]==hash) return 1;
	return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("data.in","r",stdin);
#endif
	int i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		ord1[i]=ord2[i]=i;
		scanf("%d%d",&p[i][0],&p[i][1]);
		push(p[i][0],p[i][1]);
	}
	sort(ord1,ord1+n,cmp1);
	sort(ord2,ord2+n,cmp2);
	for(i=0;i<n;i++)
		d1[ord1[i]]=i,d2[ord2[i]]=i;
	for(i=0;i<n;i++)
	{
		j=d1[i]+1,k=d2[i]+1;
		for(j=d1[i]+1,k=d2[i]+1;j<n&&k<n&&p[ord1[j]][0]==p[i][0]&&p[ord2[k]][1]==p[i][1];)
			if(p[ord1[j]][1]-p[i][1]<p[ord2[k]][0]-p[i][0]) j++;
			else if(p[ord1[j]][1]-p[i][1]>p[ord2[k]][0]-p[i][0]) k++;
			else ans+=judg(p[ord2[k]][0],p[ord1[j]][1]),j++,k++;
	}
	printf("%d\n",ans);
	return 0;
}


    /*JOKER*/
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<n;++i)
#define LL long long
using namespace std;
const int N=105;
int n,m,k,ans,a[N][N],p[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
	cin >> n >> m >> k;
	ans=k+1;
	rep(i,n) rep(j,m) scanf("%d",a[i]+j);
	if (n<=k)
    {
		rep(i,1<<n)
		{
			int res=0;
			rep(j,m)
			{
				int c=0; rep(k,n) if ((i>>k&1)^a[k][j]) ++c;
				res+=min(c,n-c);
			}
			ans=min(ans,res);
		}
	}
	else
    {
		rep(i,n)
		{
			rep(j,m) p[j]=a[i][j]; int res=0;
			rep(k,n)
			{
				int c=0; rep(j,m) if (a[k][j]^p[j]) ++c;
				res+=min(c,m-c);
			}
			ans=min(ans,res);
		}
	}
	if (ans>k) ans=-1;
	else cout << ans;
	return 0;
}


    /*JOKER*/
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<n;++i)
#define LL long long
using namespace std;
const int N=105;
int n,m,k,ans,a[N][N],p[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
    //freopen(".inp", "r", stdin);
    cin >> n >> m >> k;
	ans=k+1;
	rep(i,n) rep(j,m) cin >> a[i][j];
	if (n<=k)
    {
		rep(i,1<<n)
		{
			int res=0;
			rep(j,m)
			{
				int c=0;
                rep(k,n)
                    if ((i>>k&1)^a[k][j])
                        ++c;
				res+=min(c,n-c);
			}
			ans=min(ans,res);
		}
	}
	else
    {
		rep(i,n)
		{
			rep(j,m)
                p[j]=a[i][j];
            int res=0;
			rep(k,n)
			{
				int c=0;
				rep(j,m)
                    if (a[k][j]^p[j])
                        ++c;
				res+=min(c,m-c);
			}
			ans=min(ans,res);
		}
	}
	if (ans>k) ans=-1;
	cout << ans;
	return 0;
}


    /*JOKER*/
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<n;++i)
#define LL long long
using namespace std;
const int N=105;
int n,m,k,ans,a[N][N],p[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
    //freopen(".inp", "r", stdin);
    cin >> n >> m >> k;
	ans=k+1;
	rep(i,n) rep(j,m) cin >> a[i][j];
	if (n<=k)
    {
		rep(i,1<<n)
		{
			int res=0;
			rep(j,m)
			{
				int c=0;
                rep(k,n)
                    if ((i>>k&1)^a[k][j])
                        ++c;
				res+=min(c,n-c);
			}
			ans=min(ans,res);
		}
	}
	else
    {
		rep(i,n)
		{
			rep(j,m)
                p[j]=a[i][j];
            int res=0;
			rep(k,n)
			{
				int c=0;
				rep(j,m)
                    if (a[k][j]^p[j])
                        ++c;
				res+=min(c,m-c);
			}
			ans=min(ans,res);
		}
	}
	if (ans>k) ans=-1;
	else cout << ans;
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>

int g[100][100];
int n,m,lim;
void work1()
{
    int ans=0x7fffffff;
    for(int i=0;i<n;i++) // unchanged
    {
        int sum=0;
        for(int j=0;j<n;j++)
        {
            int cnt=0;
            for(int k=0;k<m;k++)
            {
                if(g[i][k]==g[j][k]) cnt++;
            }
            sum+=std::min(cnt,m-cnt);
        }
        ans=std::min(ans,sum);
    }
    if(ans>lim) ans=-1;
    printf("%d\n",ans);
}
int line[100];
void work2()
{
    int ans=0x7fffffff;
    for(int sta=0;sta<1<<n;sta++)
    {
        int sum=0;
        for(int i=0;i<n;i++) line[i]=1&(sta>>i);
        for(int j=0;j<m;j++)
        {
            int cnt=0;
            for(int i=0;i<n;i++)
            {
                if(g[i][j]==line[i]) cnt++;
            }
            sum+=std::min(cnt,n-cnt);
        }
        ans=std::min(ans,sum);
    }
    if(ans>lim) ans=-1;
    printf("%d\n",ans);
}
int main()
{

    while(scanf("%d%d%d",&n,&m,&lim)==3)
    {
        for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&g[i][j]);
        if(n>lim) work1();
        else work2();
    }
    return 0 ;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define INF 1000000000
//typedef __int64 LL;
#define N 105
int n,m,k,sta[N],stt[N];
int mm[N][N];
int cal(int x,int cou)
{
	int ret=0;
	for(int i=0;i<cou;i++)
	{
		ret+=(x&1); x>>=1;
	}
	return ret;
}
void test(int x,int cou)
{
	for(int i=0;i<cou; i++)
	{
		printf("%d ",x&1); x>>=1;
	}
	puts("");
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen ("in.txt" , "r" , stdin);
#endif
	scanf("%d%d%d",&n,&m,&k);
	int tmp;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&tmp);
			if(tmp)
			{
				sta[i]=sta[i]|(1<<(j-1));
				stt[j]=stt[j]|(1<<(i-1));
			}
			mm[i][j]=tmp;
		}
	}
	int mi=INF,mark;
	if(n>k)
	{	//puts(".");
		int now;
		mark=(1<<m)-1; // all one ;
		for(int i=1;i<=n;i++)
		{
			now=sta[i];//test(now,m);
			int cou=0;
			for(int j=1;j<=n;j++)
			{
				int sta1=sta[j];
				int sta2=sta[j]^mark;	//test(sta1,m); test(sta2,m);
				int s1,s2;
				s1=sta1^now; s2=sta2^now;   //test(s1,m); test(s2,m);  //printf("c %d %d ",cal(s1,n),cal(s2,n));
				cou+=min(cal(s1,m),cal(s2,m));
			}//printf("now: %d %d\n",now,cou);
			mi=min(mi,cou);
		}
	}
	else
	{
		mark=(1<<n)-1;
		for(int now=0;now<(1<<n); now++)
		{
			int cou=0;//
			for(int i=1;i<=m;i++)
			{
				int sta1=stt[i];
				int sta2=stt[i]^mark;
				int s1,s2;
				s1=sta1^now; s2=sta2^now;
				cou+=min(cal(s1,n),cal(s2,n));
			}
			mi=min(mi,cou);
		}
	}	//printf("mi: %d \n",mi);
	if(mi>k) printf("-1\n");
	else printf("%d\n",mi);

    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define INF 1000000000
//typedef __int64 LL;
#define N 105
int n,m,k,sta[N],stt[N];
int mm[N][N];
int cal(int x,int cou)
{
	int ret=0;
	for(int i=0;i<cou;i++)
	{
		ret+=(x&1); x>>=1;
	}
	return ret;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen ("in.txt" , "r" , stdin);
#endif
	scanf("%d%d%d",&n,&m,&k);
	int tmp;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&tmp);
			if(tmp)
			{
				sta[i]=sta[i]|(1<<(j-1));
				stt[j]=stt[j]|(1<<(i-1));
			}
			mm[i][j]=tmp;
		}
	}
	int mi=INF,mark;
	if(n>k)
	{	//puts(".");
		int now;
		//mark=(1<<m)-1; // all one ;
		for(int i=1;i<=n;i++)
		{
			//now=sta[i];//test(now,m);
			now=i;
			int cou=0;
			for(int j=1;j<=n;j++)
			{
				int sta1=sta[j];
				int sta2=sta[j]^mark;
				int s1,s2;
				s1=s2=0;
				for(int q=1;q<=m;q++)
				{
					if(mm[j][q]==mm[now][q]) s1++;
					else s2++;
				}
				//cou+=min(cal(s1,m),cal(s2,m));
				cou+=min(s1,s2);
			}
			mi=min(mi,cou);
		}
	}
	else
	{
		mark=(1<<n)-1;
		for(int now=0;now<(1<<n); now++)
		{
			int cou=0;//
			for(int i=1;i<=m;i++)
			{
				int sta1=stt[i];
				int sta2=stt[i]^mark;
				int s1,s2;
				s1=sta1^now; s2=sta2^now;
				cou+=min(cal(s1,n),cal(s2,n));
			}
			mi=min(mi,cou);
		}
	}
	if(mi>k) printf("-1\n");
	else printf("%d\n",mi);

    return 0;
}


#include"bits/stdc++.h"
using namespace std;
const int N=105;
int n,m,b[N],a[N][N],ans=1<<30,p;
void check()
{
	int res,bes=0;
	for(int j=1;j<=m;j++){
		res=0;
		for(int i=1;i<=n;i++){
			res+=a[i][j]^b[i];
		}
		bes+=min(res,n-res);
	}
	ans=min(ans,bes);
}
void dfs(int x)
{
	if(x==n+1){
		check();
		return ;
	}
	b[x]=1;
	dfs(x+1);
	b[x]=0;
	dfs(x+1);
}
int main()
{
	cin>>n>>m>>p;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			scanf("%d",&a[i][j]);
		}
	if(n>m){
		for(int i=1;i<=n;i++)
			for(int j=1;j<=i;j++){
				swap(a[i][j],a[j][i]);
			}
		swap(n,m);
	}
	if(n<=10)dfs(1);
	else {
		for(int j=1;j<=m;j++){
			for(int i=1;i<=n;i++)b[i]=a[i][j];
			check();
		}
	}
	if(ans>p)cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<iomanip>
#include<cstring>
#include<stdio.h>
#include<map>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<fstream>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define fab(i,a,b) for(int i=(a);i<=(b);i++)
#define fba(i,b,a) for(int i=(b);i>=(a);i--)
#define MP make_pair
#define PB push_back
#define cls(x) memset(x,0,sizeof(x))
#define lowbit(x) x&-x
#define INF 0x7ffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define sf scanf
#define pf printf
using namespace std;
typedef pair<int,int>PII;
const int N=1005;
int n,m,k,ans;
int g[N][N];
int main(){
    ios::sync_with_stdio(false);
    sf("%d %d %d",&n,&m,&k);
    rep(i,n)rep(j,m)sf("%d",&g[i][j]);
    int ans=INF;
    if(k<n){
        rep(i,n){
            int now=0;
            rep(j,n){
                int sum=0;
                rep(k,m){
                    sum+=(g[i][k]==g[j][k]);
                }
                now+=min(sum,m-sum);
            }
            if(now<ans)ans=now;
        }
    }else{
        for(int i=0;i<(1<<n);i++){
            int now=0;
            rep(j,m){
                int sum=0;
                rep(k,n){
                    sum+=(g[k][j]==((i>>k)&1));
                }
                now+=min(n-sum,sum);
            }
            if(now<ans)ans=now;
        }
    }
    if(ans<=k)pf("%d\n",ans);
    else puts("-1");
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int map[106][106];
int main()
{
    int n,m,k,key=16;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&map[i][j]);
    if(k<n)
    {
        for(int i=1;i<=n;i++)
        {
            int ans=0;
            for(int j=1;j<=n;j++)
            {
                int sum=0;
                for(int k=1;k<=m;k++)
                {
                    sum+=(map[i][k]==map[j][k]);
                }
                sum=min(sum,m-sum);
                ans+=sum;
            }
            if(ans<key)
                key=ans;
        }
    }
    else
    {
        for(int i=0;i<=(1<<n)-1;i++)
        {
            int ans=0;
            for(int j=1;j<=m;j++)
            {
                int sum=0;
                for(int k=1;k<=n;k++)
                {
                    sum+=(map[k][j]==((i>>(k-1))&1));
                }
                sum=min(sum,n-sum);
                ans+=sum;
            }
            if(ans<key)
                key=ans;
        }
    }
    if(key>k)
        puts("-1");
    else
        printf("%d\n",key);
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int map[106][106];
int main()
{
    int n,m,k,key=16;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&map[i][j]);
    if(k<n)
    {
        for(int i=1;i<=n;i++)
        {
            int ans=0;
            for(int j=1;j<=n;j++)
            {
                int sum=0;
                for(int k=1;k<=m;k++)
                {
                    sum+=(map[i][k]==map[j][k]);
                }
                sum=min(sum,m-sum);
                ans+=sum;
            }
            if(ans<key)
                key=ans;
        }
    }
    else
    {
        for(int i=0;i<=1<<m;i++)
        {
            int ans=0;
            for(int j=1;j<=n;j++)
            {
                int sum=0;
                for(int k=1;k<=m;k++)
                {
                    sum+=(map[j][k]==((i>>(k-1))&1));
                }
                sum=min(sum,m-sum);
                ans+=sum;
            }
            if(ans<key)
                key=ans;
        }
    }
    if(key>k)
        puts("-1");
    else
        printf("%d\n",key);
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int om[100][100];
int tmp;
int req;
int k;
int r;
int c;

int getans()
{
    int ans = 2147483647;
    for (int key = 0;key < r;key++)
    {
        req = 0;
        for (int i = 0;i < r;i++)
        {
            tmp = 0;
            for (int j = 0;j < c;j++)
                tmp += (om[i][j] == om[key][j]);
            req += min(tmp, c-tmp);
        }
        ans = min(ans, req);
    }
    for (int key = 0;key < c;key++)
    {
        req = 0;
        for (int i = 0;i < c;i++)
        {
            tmp = 0;
            for (int j = 0;j < r;j++)
                tmp += (om[j][i] == om[j][key]);
            req += min(tmp, r-tmp);
        }
        ans = min(ans, req);
    }
    return ans;
}

int main()
{
    int ans = 2147483647;
    scanf("%d%d%d", &r, &c, &k);
    for (int i = 0;i < r;i++) for (int j = 0;j < c;j++)
        scanf("%d", &om[i][j]);
    if (r <= 10)
    { // have enough changes, might want to just modify every column
        int orig = 0;
        for (int i = 0;i < r;i++)
            orig += (om[i][0] << i);
        for (int key = 0;key < (1<<r);key++)
        {
            int temp = 0;
            for (int i = 0;i < r;i++)
            {
                temp += (((orig & (1 << i)) ^ (key & (1 << i))) >> i);
                om[i][0] = (key & (1 << i)) >> i;
            }
            temp += getans();
            if (temp < ans)
                ans = temp;
        }
        if (ans <= k)
            printf("%d\n", ans);
        else
            printf("-1\n");
        return 0;
    }
    ans = getans();
    if (ans <= k)
        printf("%d\n", ans);
    else
        printf("-1\n");
    return 0;
}


#include <iostream>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <string.h>
#include <stdio.h>
#define sf scanf
#define pf printf
#define ll long long

#define clr(x) memset(x,0,sizeof(x))
#define _clr(x) memset(x,-1,sizeof(x))
#define fr(i,a,b) for(int i = a; i < b; ++i )

using namespace std;

int n, m, k;
int a[600][600];

int solve()
{
    if( n < m )
    {
        for( int i = 0; i < n; ++i )
        {
            for( int j = i+1; j < m; ++j )
            {
                swap( a[i][j], a[j][i] );
            }
        }
        swap( n, m );
    }

    int ans = k+1;
    if( n <= k )
    {
        for( int i = 0; i < ( 1 << m ); ++i )
        {
            int num = 0;
            for( int j = 0; j < n; ++j )
            {
                int cnt = 0;
                for( int l = 0; l < m; ++l )
                {
                    cnt += ( ( ( 1 << l ) & i ) && 1 )^ a[j][l];
                }
                num += min( cnt, m - cnt );
            }
            ans = min( ans, num );
        }
    }
    else
    {
        for( int i = 0; i < n; ++i )
        {
            int num = 0;
            for( int j = 0; j  < n ;++j )
            {
                if( i == j ) continue;
                int cnt = 0;
                for( int l = 0; l < m; ++l )
                {
                    cnt += a[i][l] ^ a[j][l];
                }
                num += min( cnt, m-cnt );
            }
            ans = min( ans, num );
        }
    }
    printf("%d\n",ans>k? -1:ans);
}

int main()
{
    while( cin>>n>>m>>k )
    {
        for( int i = 0; i < n; ++i )
        {
            for( int j = 0; j < m; ++j )
            {
                cin>>a[i][j];
            }
        }
        solve();
    }

}


#include <iostream>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <string.h>
#include <stdio.h>
#define sf scanf
#define pf printf
#define ll long long

#define clr(x) memset(x,0,sizeof(x))
#define _clr(x) memset(x,-1,sizeof(x))
#define fr(i,a,b) for(int i = a; i < b; ++i )

using namespace std;

int n, m, k;
int a[600][600];

int solve()
{
    if( n < m )
    {
        for( int i = 0; i < n; ++i )
        {
            for( int j = i+1; j < m; ++j )
            {
                swap( a[i][j], a[j][i] );
            }
        }
        swap( n, m );
    }

    int ans = k+1;
    if( n <= k )
    {
        for( int i = 0; i < ( 1 << m ); ++i )
        {
            int num = 0;
            for( int j = 0; j < n; ++j )
            {
                int cnt = 0;
                for( int l = 0; l < m; ++l )
                {
                    cnt += ( 1 << l ) ^ i;
                }
                num = min( cnt, m - cnt );
            }
            ans = min( ans, num );
        }
    }
    else
    {
        for( int i = 0; i < n; ++i )
        {
            int num = 0;
            for( int j = 0; j  < n ;++j )
            {
                if( i == j ) continue;
                int cnt = 0;
                for( int l = 0; l < m; ++l )
                {
                    cnt += a[i][l] ^ a[j][l];
                }
                num += min( cnt, m-cnt );
            }
            ans = min( ans, num );
        }
    }
    printf("%d\n",ans>=k? -1:ans);
}

int main()
{
    while( cin>>n>>m>>k )
    {
        for( int i = 0; i < n; ++i )
        {
            for( int j = 0; j < m; ++j )
            {
                cin>>a[i][j];
            }
        }
        solve();
    }

}


#include <iostream>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <string.h>
#include <stdio.h>
#define sf scanf
#define pf printf
#define ll long long

#define clr(x) memset(x,0,sizeof(x))
#define _clr(x) memset(x,-1,sizeof(x))
#define fr(i,a,b) for(int i = a; i < b; ++i )

using namespace std;

int n, m, k;
int a[600][600];

int solve()
{
    if( n < m )
    {
        for( int i = 0; i < n; ++i )
        {
            for( int j = i+1; j < m; ++j )
            {
                swap( a[i][j], a[j][i] );
            }
        }
        swap( n, m );
    }

    int ans = k+1;
    if( n <= k )
    {
        for( int i = 0; i < ( 1 << m ); ++i )
        {
            int num = 0;
            for( int j = 0; j < n; ++j )
            {
                int cnt = 0;
                for( int l = 0; l < m; ++l )
                {
                    cnt += ( 1 << l ) ^ i;
                }
                num = min( cnt, m - cnt );
            }
            ans = min( ans, num );
        }
    }
    else
    {
        for( int i = 0; i < n; ++i )
        {
            int num = 0;
            for( int j = 0; j  < n ;++j )
            {
                if( i == j ) continue;
                int cnt = 0;
                for( int l = 0; l < m; ++l )
                {
                    cnt += a[i][l] ^ a[j][l];
                }
                num += min( cnt, m-cnt );
            }
            ans = min( ans, num );
        }
    }
    printf("%d\n",ans>k? -1:ans);
}

int main()
{
    while( cin>>n>>m>>k )
    {
        for( int i = 0; i < n; ++i )
        {
            for( int j = 0; j < m; ++j )
            {
                cin>>a[i][j];
            }
        }
        solve();
    }

}


// TestPrj.cpp : main project file.

//#include "stdafx.h"

/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9
typedef long long Long;
//typedef __int64 Long;
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }

const int maxn = 105;
int A[maxn][maxn];

int main()
{
	#ifdef localhost
	freopen("E://input.txt","r",stdin);
	//freopen("E://output.txt","w",stdout);
	#endif

	int i,j,m0,m1,n,m,k,ans = inf,val,a,b,s0,s1,mask; cin >> n >> m >> k;
	fo(i,0,n)fo(j,0,m)cin >> A[i][j];
	if(m > k)
	{
		fo(m0,0,m)
		{
			val = 0;
			fo(m1,0,m)if(m0 != m1)
			{
				s0 = s1 = 0;
				fo(i,0,n)if(A[i][m0] == A[i][m1])s0++; else s1++;
				val += min(s0,s1);
			}
			ans = min(ans,val);
		}
	}
	else
	{
		fo(mask,0,two(m))
		{
			val = 0;
			fo(i,0,n)
			{
				m0 = m1 = s0 = s1 = 0;
				fo(j,0,m)
				{
					if(contain(mask,j))
					{
						if(A[i][j] == 0)s0++; else s1++;
					}
					else
					{
						if(A[i][j] == 0)m0++; else m1++;
					}
				}
				val += min(m0+s1,s0+m1);
			}
			ans = min(ans,val);
		}
	}
	if(ans > k)ans = -1;
	cout << ans << endl;

	return 0;
}


/*
С подсвечником не всё так просто -
Он здесь стоит который год.
Но свечи заменяют солнце
И речь всегда о них идёт.

А ночь, как должно, наступает
На землю, поглощая всё -
Лишь дождь пестреющую стаю
Слегка светящихся несёт.

Но отблеск отдаёт подсвечник
От еле видных в окна звёзд,
Который затмевает свечи
И первый глазу свет даёт.
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iterator>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>

using namespace std;

int main()
{
	int i,j,k;
	int N,M,K;
	cin >> N >> M >> K;
	vector< vector<int> > a(N,vector<int>(M));
	for (i=0;i<N;i++)
		for (j=0;j<M;j++)
			cin >> a[i][j];
	if (M>N && M!=1)
	{
		vector< vector<int> > tmp(M,vector<int>(N));
		for (i=0;i<N;i++)
			for (j=0;j<M;j++)
				tmp[j][i]=a[i][j];
		a=tmp;
		swap(N,M);
	}
	int ans=1000*1000*1000;
	int rev,sum_rev;
	if (M>K)
	{
		for (k=0;k<N;k++)
		{
			sum_rev=0;
			for (i=0;i<N;i++)
			{
				rev=0;
				for (j=0;j<M;j++)
					if (a[i][j]!=a[k][j])
						rev++;
				sum_rev+=min(rev,M-rev);
			}
			ans=min(ans,sum_rev);
		}
	}
	else
	{
		for (k=0;k<(1<<M);k++)
		{
			vector<int> mask(M);
			for (i=0;i<M;i++)
				mask[i]=((k&(1<<i))>0);
			sum_rev=0;
			for (i=0;i<N;i++)
			{
				rev=0;
				for (j=0;j<M;j++)
					rev+=(a[i][j]!=mask[j]);
				sum_rev+=min(rev,M-rev);
			}
			ans=min(ans,sum_rev);
		}
	}
	if (ans>K)
		cout << "-1";
	else
		cout << ans;
	cout << endl;
}


#include<cstdio>
#include<iostream>
#define N 100
using namespace std;

int M[N+5][N+5];

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cin>>M[i][j];
        }
    }
    int mini=1000;
    if(m<=k){
        for(int mask=0;mask<(1<<m);++mask){
            int ct=0;
            for(int i=0;i<n;++i){
                int r1=0,r2=0;
                for(int j=0;j<m;++j){
                    if( (mask>>j)&1 )r1+=(M[i][j]==0);
                    else r1+=(M[i][j]==1);
                }
                for(int j=0;j<m;++j){
                    if( (mask>>j)&1 )r2+=(M[i][j]==1);
                    else r2+=(M[i][j]==0);
                }
                ct+=min(r1,r2);
            }
            mini=min(mini,ct);
        }
        if(mini<=k)cout<<mini<<endl;
        else puts("-1");
    }
    else{
        for(int fix=0;fix<m;++fix){
            int ct=0;
            for(int j=0;j<m;++j){
                if(j!=fix){
                    int r1=0,r2=0;
                    for(int i=0;i<n;++i)r1+=(M[i][j]==M[i][fix]);
                    for(int i=0;i<n;++i)r2+=(M[i][j]!=M[i][fix]);
                    ct+=min(r1,r2);
                }
            }
            mini=min(mini,ct);
        }
        if(mini<=k)cout<<mini<<endl;
        else puts("-1");
    }
}


#include<cstdio>
#include<iostream>
#define N 100
using namespace std;

int M[N+5][N+5];

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cin>>M[i][j];
        }
    }
    int mini=1000;
    if(m<=k){
        for(int mask=0;mask<(1<<m);++mask){
            int ct=0;
            for(int i=0;i<n;++i){
                int r1=0,r2=0;
                for(int j=0;j<m;++i){
                    if( (mask>>j)&1 )r1+=(M[i][j]==0);
                    else r1+=(M[i][j]==1);
                }
                for(int j=0;j<m;++i){
                    if( (mask>>j)&1 )r2+=(M[i][j]==1);
                    else r2+=(M[i][j]==0);
                }
                ct+=min(r1,r2);
            }
            mini=min(mini,ct);
        }
        if(mini<=k)cout<<mini<<endl;
        else puts("-1");
    }
    else{
        for(int fix=0;fix<m;++fix){
            int ct=0;
            for(int j=0;j<m;++j){
                if(j!=fix){
                    int r1=0,r2=0;
                    for(int i=0;i<n;++i)r1+=(M[i][j]==M[i][fix]);
                    for(int i=0;i<n;++i)r2+=(M[i][j]!=M[i][fix]);
                    ct+=min(r1,r2);
                }
            }
            mini=min(mini,ct);
        }
        if(mini<=k)cout<<mini<<endl;
        else puts("-1");
    }
}


#include <bits/stdc++.h>

#define repp(i,a,b) for(int i = a; i <= b; i++)
#define rep(i,n) for(int i = 1; i <= n; i++)
#define onesll(c) __builtin_popcountll(c)
#define ones(c) __builtin_popcount(c)
#define all(c) c.begin(), c.end()
#define llu unsigned long long
#define sz(c) (int) c.size()
#define pb(x) push_back(x)
#define lb lower_bound
#define up upper_bound
#define ll long long
#define endl "\n"
using namespace std;
// stringstream
stringstream ss;

// Coding begins here
const int N = 4e5 + 5;
const int mod = 1e9 + 7;
map <int,int> mp;
int main(){
	int n; cin >> n;
	string s; cin >> s;
	int sum = 0, ans = 0; mp[0] = -1;
	for(int i = 0; i < sz(s); i++){
		if(s[i] == '1') sum++; else sum--;
		if(mp.find(sum) != mp.end())
		ans = max(ans, i - mp[sum]);
		else mp[sum] = i;
	}
	cout << ans << endl;
}


#include <stdio.h>

unsigned long long s[2];
unsigned long long xorshift128plus() {
	unsigned long long x = s[0];
	const unsigned long long y = s[1];
	x ^= x << 23;
	s[1] = x ^ y ^ (x >> 17) ^ (y >> 26);
	return s[0] = y;
}

const int MX = 1000;

int C[MX][MX];
int H[MX][MX];

int main() {
	int T;
	scanf("%d", &T);
	for (int t = 0; t < T; t++) {
		int n, Cmax, Hmax;
		scanf("%d %d %d", &n, &Cmax, &Hmax);
		for (int i = 0; i < n; i++) {
			C[i][i] = 0;
			scanf("%llu %llu", &s[0], &s[1]);
			for (int j = i + 1; j < n; j++) {
				C[i][j] = C[j][i] = xorshift128plus() % (Cmax + 1);
			}
		}

		for (int i = 0; i < n; i++) {
			scanf("%llu %llu", &s[0], &s[1]);
			for (int j = 0; j < n; j++) {
				H[i][j] = xorshift128plus() % (Hmax + 1);
			}
		}

		// solve here

	}

	return 0;
}


#include <bits/stdc++.h>

#define repp(i,a,b) for(int i = a; i <= b; i++)
#define rep(i,n) for(int i = 1; i <= n; i++)
#define onesll(c) __builtin_popcountll(c)
#define ones(c) __builtin_popcount(c)
#define all(c) c.begin(), c.end()
#define llu unsigned long long
#define sz(c) (int) c.size()
#define pb(x) push_back(x)
#define lb lower_bound
#define up upper_bound
#define ll long long
#define endl "\n"
using namespace std;
// stringstream
stringstream ss;

// Coding begins here
const int N = 4e5 + 5;
const int mod = 1e9 + 7;
map <int,int> mp;
int main(){
	int n; cin >> n;
	string s; cin >> s;
	int sum = 0, ans = 0; mp[0] = 1;
	for(int i = 0; i < sz(s); i++){
		if(s[i] == '1') sum++; else sum--;
		if(mp.find(sum) != mp.end())
		ans = max(ans, i - mp[sum]);
		else mp[sum] = i;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	int ONE = 0;
	int ZERO = 0;

	for(int i = 0 ; i< s.size() ; i++)
	{
		if(s[i] == '1')
			ONE++;
		else
			ZERO++;
	}
	int fp = -1;
	int lp = -1;
	char wanted ='0';
	if(ONE == s.size() || ZERO == s.size()){
		cout << 0 << endl;
		return(0);
	}
	if(ZERO == ONE)
	{
		cout<<s.size()<<endl;
		return(0);
	}
	if(ZERO < ONE)
		wanted = '1';
	if(ZERO < ONE){
		for(int i = 0 ; i < s.size() ; i++){
			if(s[i] == '0'){
				if(fp == -1)
					fp = i;
				lp = i;
			}
		}
	}
	else{
		for(int i = 0 ; i < s.size() ; i++){
			if(s[i] == '1'){
				if(fp == -1)
					fp = i;
				lp = i;
			}
		}
	}

	int count = 0;
	//cout<<fp<<" "<<lp<<endl;
	for(int i = fp ; i <= lp ;i++){
		if(s[i] == wanted)
			count++;
	}
	//cout << count <<" "<< lp-fp+1<<endl;
	if(count == 0){
		cout << 2*(lp-fp+1)<<endl;
	}
	else if(count <=(lp-fp+1-count ) ){
		cout << 2*(lp-fp+1) -2*count<<endl;
	}
	else{
		int ans,ans1;
		int nonwanted = lp-fp+1 - count;
		// cout<<nonwanted<<endl;
		int count2 = count;
		int nonwanted2 = nonwanted;
		for(int  i = lp ; i>= fp ; i--){
			if(count == nonwanted){
				ans = count;
				break;
			}
			else{
				if(s[i] == wanted){
					count--;
				}
				else
					nonwanted--;
			}
		}
		count = count2;
		nonwanted = nonwanted2;
		for(int  i = fp ; i<= lp ; i++){
			if(count == nonwanted){
				ans1 = count;
				break;
			}
			else{
				if(s[i] == wanted){
					count--;
				}
				else
					nonwanted--;
			}
		}

		cout<<max(ans,ans1)*2;
	}
}