#include <bits/stdc++.h>

// loops
#define rep(i, n) for(int i=0; i<n; i++)
#define repA(i, a, n) for(int i=a; i<n; i++)
#define repD(i, a, n) for(int i=a; i>=n; i--)
#define trav(it, ctr) for(auto it=ctr.begin(); it!=ctr.end(); it++)
#define travR(it, ctr) for(auto it=ctr.rbegin(); it!=ctr.rend(); it++)

// I/O
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define p(x) cout<<x<<"\n"
#define pp(x, y) cout<<x<<" "<<y<<"\n"
#define lbr cout<<"\n"

// container and contants
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define hell (int)1e9
#define ms(x) memset(x, 0, sizeof(x))
// namespaces
using namespace std;

// typedefs
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

typedef map<int, int> mii;
typedef unsigned long long ull;
typedef priority_queue<int> pq;

// global constants
const int inf=1e9+7;
#define M 1000000007

#define ll long long
ll power(ll x,ll y)
{
    ll res = 1;
    x = x % M;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % M;

        y = y>>1;
        x = (x*x) % M;
    }
    return res;
}
map<ll,vector<ll>> adj;
map<ll,vector<ll>> connect;
map<ll,ll> visited;

void dfs(ll curr,ll ind)
{
    visited[curr]=1;
    connect[ind].pb(curr);

    for (auto x:adj[curr])
    {
        if (visited[x]!=1)
        {
            dfs(x,ind);
        }

    }

}

ll a[200005],b[200005];

int main()
{
    ll t;cin>>t;
 while(t--){
  ll a,b;
  cin>>a>>b;
  ll n,k;
  ll diff=abs(b-a);
  n=100005;
  k=diff;
  //cin>>n>>k;
  ll flag=0;

 //cout<<a<<" "<<b<<endl;
 //if (diff==0){cout<<0<<endl;continue;}

 ll ans=-1,mx,ka=k;
 ll low=0,high=n;
  while(low<=high){
      ll mid=low+high;mid/=2;
      ll ta=mid*(mid+1);ta/=2;
    // cout<<low<<" "<<mid<<" "<<high<<endl;
      if (ta>ka){
          high=mid-1;
          mx=max(mx,mid);
      }
      else if (ta<=ka){
          low=mid+1;
          ans=mid;
      }
  }

    for (ll i=ans;i<=ans+3;i++){
        if ((i*(i+1))/2-diff<0)
        continue;

        if (((i*(i+1))/2-diff)%2==0){
            ans=i;
            break;
        }

    }

  p(ans);

 }
    return 0;
}


#include <bits/stdc++.h>

// loops
#define rep(i, n) for(int i=0; i<n; i++)
#define repA(i, a, n) for(int i=a; i<n; i++)
#define repD(i, a, n) for(int i=a; i>=n; i--)
#define trav(it, ctr) for(auto it=ctr.begin(); it!=ctr.end(); it++)
#define travR(it, ctr) for(auto it=ctr.rbegin(); it!=ctr.rend(); it++)

// I/O
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define p(x) cout<<x<<"\n"
#define pp(x, y) cout<<x<<" "<<y<<"\n"
#define lbr cout<<"\n"

// container and contants
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define hell (int)1e9
#define ms(x) memset(x, 0, sizeof(x))
// namespaces
using namespace std;

// typedefs
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

typedef map<int, int> mii;
typedef unsigned long long ull;
typedef priority_queue<int> pq;

// global constants
const int inf=1e9+7;
#define M 1000000007

#define ll long long
ll power(ll x,ll y)
{
    ll res = 1;
    x = x % M;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % M;

        y = y>>1;
        x = (x*x) % M;
    }
    return res;
}
map<ll,vector<ll>> adj;
map<ll,vector<ll>> connect;
map<ll,ll> visited;

void dfs(ll curr,ll ind)
{
    visited[curr]=1;
    connect[ind].pb(curr);

    for (auto x:adj[curr])
    {
        if (visited[x]!=1)
        {
            dfs(x,ind);
        }

    }

}

ll a[200005],b[200005];

int main()
{
    ll t;cin>>t;
 while(t--){
  ll a,b;
  cin>>a>>b;
  ll n,k;
  ll diff=abs(b-a);
  n=100005;
  k=diff;
  //cin>>n>>k;
  ll flag=0;

 //cout<<a<<" "<<b<<endl;
 //if (diff==0){cout<<0<<endl;continue;}

 ll ans=-1,mx,ka=k;
 ll low=0,high=n;
  while(low<=high){
      ll mid=low+high;mid/=2;
      ll ta=mid*(mid+1);ta/=2;
    // cout<<low<<" "<<mid<<" "<<high<<endl;
      if (ta>ka){
          high=mid-1;
          mx=max(mx,mid);
      }
      else if (ta<=ka){
          low=mid+1;
          ans=mid;
      }
  }

    for (ll i=ans;i<=ans+10;i++){
        if ((i*(i+1))/2-diff<0)
        continue;

        if (((i*(i+1))/2-diff)%2==0){
            ans=i;
            break;
        }

    }

  p(ans);

 }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

long long sum[100100];
int main(){
	int t, a, b;
	cin >> t;
	sum[1] = 1;
	for(int i = 2; i < 100100; i ++){
		sum[i] = sum[i - 1] + i;
	}
	while(t --){
		cin >> a >> b;
		if(a > b)
			swap(a, b);
		int x = b - a;
		int ans = lower_bound(sum, sum + 10010, x) - sum;
		if((sum[ans] - x) % 2 == 1){
			if(ans % 2 == 1){
				cout << ans + 2 << endl;
			}
			else{
				cout << ans + 1 << endl;
			}
		}
		else
			cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int t, a, b;
	cin >> t;
	while(t --){
		cin >> a >> b;
		if(a > b)
			swap(a, b);
		int i;
		int ans = 0;
		for(i = 1; i ;i ++){
			if(a + i <= b){
				a += i;
				ans ++;
			}
			else break;
		}
		if(a == b){
			cout << ans << endl;
			continue;
		}
		int x = b - a;
		int xx = i - x;
		if(xx == 1){
			cout << ans + 2 << endl;
			continue;
		}
		if(xx % 2 == 1)	ans += 3;
		else	ans ++;
		cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int t, a, b;
	cin >> t;
	while(t --){
		cin >> a >> b;
		if(a > b)
			swap(a, b);
		int i;
		int ans = 0;
		for(i = 1; i ;i ++){
			if(a + i <= b)
				a += i, ans ++;
			else break;
		}
		ans += 2 * (b - a);
		cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

long long sum[100100];
int main(){
	int t, a, b;
	cin >> t;
	for(int i = 1; i < 100100; i ++){
		sum[i] = sum[i - 1] + i;
	}
	while(t --){
		cin >> a >> b;
		if(a > b)
			swap(a, b);
		int x = b - a;
		int ans = lower_bound(sum, sum + 100100, x) - sum;
		if((sum[ans] - x) % 2 == 1){
			if(ans % 2 == 1){
				cout << ans + 2 << endl;
			}
			else{
				cout << ans + 1 << endl;
			}
		}
		else
			cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int sum[100100];
int main(){
	int t, a, b;
	cin >> t;
	sum[1] = 1;
	for(int i = 2; i < 100100; i ++){
		sum[i] = sum[i - 1] + i;
	}
	while(t --){
		cin >> a >> b;
		if(a > b)
			swap(a, b);
		int x = b - a;
		int ans = lower_bound(sum, sum + 10010, x) - sum;
		if((sum[ans] - x) % 2 == 1){
			if(ans % 2 == 1){
				cout << ans + 2 << endl;
			}
			else{
				cout << ans + 1 << endl;
			}
		}
		else
			cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int t, a, b;
	cin >> t;
	while(t --){
		cin >> a >> b;
		if(a > b)
			swap(a, b);
		int i;
		int ans = 0;
		for(i = 1; i ;i ++){
			if(a + i <= b){
				a += i;
				ans ++;
			}
			else break;
		}
		if(a == b){
			cout << ans << endl;
			continue;
		}
		int x = b - a;
		int xx = i - x;
		if(x == 1){
			cout << ans + 2 << endl;
			continue;
		}
		if(xx % 2 == 1)	ans += 3;
		else	ans ++;
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		ll a,b;
		int flag=0;
		ll ans=-1;
		cin>>a>>b;
		if(a>b) swap(a,b);
		for(int i=0;;i++)
		{
			a+=i;ans++;
			if(a==b)
			{
				cout<<ans<<endl;flag=1;
			}
			else if(a>b)
			{
				if((a+b)%2!=0) continue;
				else
				{
					ll temp=(a+b)/2;
					if(temp<=(i-1)+i)
					{
						cout<<ans<<endl;flag=1;
					}
				}

			}
			if(flag) break;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		ll a,b,temp;
		ll fac=1;
		ll ans=0;
		cin>>a>>b;
		if(a>b) temp=a,a=b,b=temp;
		while(1)
		{
			if(a+fac<=b)
			{
				ans++;
				a+=fac;
			}
			else
			{
				cout<<ans+(b-a)*2<<endl;break;
			}
			fac++;

		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		ll a,b,sumn=0;
		int flag=0;
		ll ans=-1;
		cin>>a>>b;
		if(a>b) swap(a,b);
		for(int i=0;;i++)
		{
			a+=i;ans++;
			sumn+=i;
			if(a==b)
			{
				cout<<ans<<endl;flag=1;
			}
			else if(a>b)
			{
				if((a+b)%2!=0) continue;
				else
				{
					ll temp=(a+b)/2;
					if(temp<=sumn)
					{
						cout<<ans<<endl;flag=1;
					}
				}

			}
			if(flag) break;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		ll a,b,temp;
		ll fac=1;
		ll ans=0;
		cin>>a>>b;
		if(a>b) temp=a,a=b,b=temp;
		while(1)
		{
			if(a+fac<b)
			{
				ans++;
				a+=fac;
			}
			else
			{
				cout<<ans+(b-a)*2<<endl;break;
			}
			fac++;

		}
	}
	return 0;
}


#include <iostream>
#include<string>
#include<sstream>
using namespace std;

int main()
{
    int n  , m ;
    cin>>n>>m ;
    int max[m];
    char c[n][m];
    int t[n][m] ;
    for ( int i=0 ; i<n ; i++)
    {
        for ( int j=0 ; j<m ; j++)
        {
            max[j]=0 ;
            cin>>c[i][j] ;
            stringstream ss ;
            char s ;
            int z ;
            ss<<c[i][j] ;
            ss>>z ;
            t[i][j]=z ;
        }
    }
    for ( int i=0 ; i<m; i++)
    {
        for ( int j=0 ; j<n; j++)
        {
            if (t[j][i]>max[i])
                max[i]=t[j][i] ;
        }
            cout<<max[i]<<"    ";
    }
    int h=0 , hh=0 ;
    for ( int i=0 ; i<n ; i++)
    {
        h=0 ;
        for ( int j=0 ; j<m ; j++)
        {
            if (t[i][j]==max[j])
            {
                h++;
            }
        }
        if (h>0)
            hh++;
    }

cout<<hh ;

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, m ;
    cin>>n>>m ;
       int maxrow[n] , maxcol[m] ;
    char c[n][m];
    int a[n][m] ;
    for ( int i=0 ; i<n ; i++)
        maxrow[i]=0 ;
    for ( int j=0; j<m ; j++)
        maxcol[j]=0 ;
    for ( int i=0 ; i<n ; i++)
    {
        for ( int j=0 ; j<m ; j++)
            {
            cin>>c[i][j] ;
            a[i][j] = c[i][j] - '0';
            if (   a[i][j]>maxcol[j])
                    {maxcol[j]=a[i][j] ;
                    //cout<<maxcol[j]<<endl;}
            }
    }
}
    int x=0 ;
    for ( int i=0 ; i<n ; i++ )
    {
        for ( int j=0 ; j<m ; j++)
        {
            if (a[j][i]>maxrow[i])
            maxrow[i]=a[i][j] ;

    }}
    for ( int i=0 ; i<n; i++)
    {
        for ( int j=0 ; j<m ; j++)
        {
            if (a[i][j]==maxcol[j] && a[i][j]==maxrow[i])
                x++ ;

        }
    }
cout<<x<<endl;

    return 0;
}


#include <iostream>
#include<vector>
#include<sstream>

using namespace std;

int main()
{
    int    z , y,t=0 , m=0 ;
    vector<int>max;
    int n;
    cin>>z>>y;
    int x[z][y];
    for (int i=0 ; i<z; i++)
    {
        for ( int j=0 ; j<y ; j++)
        {
            cin>>x[i][j];
        }
    }
    for (int i=0 ; i<y ; i++)
    {
        m=0;
        for (int j=0 ; j<z ; j++)
        {
            if (x[j][i]>=m)
            {
                m=x[j][i];
        }}
        max.push_back(m);
    }
    for ( int i=0 ; i<max.size() ; i++)
        cout<<max[i]<<" ";
    for (int i=0 ; i<z ; i++)
    {
        n=0;
        for (int j=0 ; j<y ; j++)
        {
            if (x[i][j]==max[j])
            {
                n++;
            }
        }
        if (n>=1)
            t+=1;
    }
    cout<<endl<<t<<endl;

    return 0;
}


#include <iostream>
#include<vector>
#include<sstream>

using namespace std;

int main()
{
    int    z , y,t=0 , m=0 ;
    vector<int>max;
    int n;
    cin>>z>>y;
    int x[z][y];
    for (int i=0 ; i<z; i++)
    {
        for ( int j=0 ; j<y ; j++)
        {
            cin>>x[i][j];
        }
    }
    for (int i=0 ; i<y ; i++)
    {
        m=0;
        for (int j=0 ; j<z ; j++)
        {
            if (x[j][i]>=m)
            {
                m=x[j][i];
        }}
        max.push_back(m);
    }
    for (int i=0 ; i<z ; i++)
    {
        n=0;
        for (int j=0 ; j<y ; j++)
        {
            if (x[i][j]==max[j])
            {
                n++;
            }
        }
        if (n>=1)
            t+=1;
    }
    cout<<endl<<t<<endl;

    return 0;
}


#include <iostream>
#include<string>
#include<sstream>
using namespace std;

int main()
{
    int n  , m ;
    cin>>n>>m ;
    int max[m];
    char c[n][m];
    int t[n][m] ;
    for ( int i=0 ; i<n ; i++)
    {
        for ( int j=0 ; j<m ; j++)
        {
            max[j]=0 ;
            cin>>c[i][j] ;
            stringstream ss ;
            char s ;
            int z ;
            ss<<c[i][j] ;
            ss>>z ;
            t[i][j]=z ;
        }
    }
    for ( int i=0 ; i<m; i++)
    {
        for ( int j=0 ; j<n; j++)
        {
            if (t[j][i]>max[i])
                max[i]=t[j][i] ;
        }
    }
    int h=0 , hh=0 ;
    for ( int i=0 ; i<n ; i++)
    {
        h=0 ;
        for ( int j=0 ; j<m ; j++)
        {
            if (t[i][j]==max[j])
            {
                h++;
            }
        }
        if (h>0)
            hh++;
    }

cout<<hh ;

    return 0;
}


#include <iostream>
#include<vector>
#include<sstream>

using namespace std;

int main()
{
    int    z , y ,t=0 , m=0 ;
    vector<int>max;
    int n;
    cin>>z>>y;
    int x[z][y];
    for (int i=0 ; i<z; i++)
    {
        for ( int j=0 ; j<y ; j++)
        {
            cin>>x[i][j];
        }
    }
    for (int i=0 ; i<y ; i++)
    {
        m=0;
        for (int j=0 ; j<z ; j++)
        {
            if (x[j][i]>=m)
            {
                m=x[j][i];
        }}
        max.push_back(m);
    }
    for (int i=0 ; i<z ; i++)
    {
        n=0;
        for (int j=0 ; j<y ; j++)
        {
            if (x[i][j]==max[j])
            {
                n++;
            }
        }
        if (n>=1)
            t+=1;
    }
    cout<<endl<<t<<endl;

    return 0;
}


#include <iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;

int main()
{
int z , min , max , t=0 ,n;
vector<int>x;
cin>>n ;
for (int i=0 ; i<n ; i++)
{
    cin>>z;
    x.push_back(z);
}
max=x[0] ;
min=x[0] ;
for (int i=0 ; i<x.size() ; i++)
{
    if (x[i]>max)
        max=x[i] ;
}
for (int i=0 ; i<x.size() ; i++)
{ if (x[i]<min)
min=x[i] ;}

for (int i=x.size() ; i>0 ; i--)
{
    if (x[i]==max)
    {swap( x[i] , x[i-1] ) ;
    t++;}
}
for (int i=0 ; i<x.size()-1 ; i++)
    {if (x[i]==min)
{
    swap (x[i], x[i+1]) ;
    t++ ;}}
cout<<t<<endl;

    return 0;
}


#include <iostream>
#include<vector>
#include<sstream>

using namespace std;

int main()
{
    int    z , y,t=0 , m=0 ;
    vector<int>max;
    int n;
    cin>>z>>y;
    char u[z][y];
    int  x[z][y];
    for (int i=0 ; i<z; i++)
    {
        for ( int j=0 ; j<y ; j++)
        {
            stringstream ss;
            cin>>u[i][j];
            ss<<u[i][j];
            ss>>x[i][j];

        }
    }
    for (int i=0 ; i<y ; i++)
    {
        m=0;
        for (int j=0 ; j<z ; j++)
        {
            if (x[j][i]>=m)
            {
                m=x[j][i];
        }}
        max.push_back(m);
    }
    for (int i=0 ; i<z ; i++)
    {
        n=0;
        for (int j=0 ; j<y ; j++)
        {
            if (x[i][j]==max[j])
            {
                n++;
            }
        }
        if (n>=1)
            t+=1;
    }
    cout<<endl<<t<<endl;

    return 0;
}


#include <stdio.h>

int main(void) {
    // your code goes here
    int n, m,tmp=0,c=0;
    scanf("%d%d",&n,&m);
    int marks[101][101]={0};

    for(int i=0 ;i<n ;i++){
        for(int j=0 ;j<m ;j++){
            scanf("%d",&marks[i][j]);
        }
    }

    for(int i=0 ;i<m ;i++){
        for(int j=0 ;j<n ;j++){
            if(marks[j][i]<marks[j+1][i]){
            tmp=marks[j][i];
            marks[j][i]=marks[j+1][i];
            marks[j+1][i]=tmp;
            }
        }
    }

    for(int i=0 ;i<m ; i++){
        if(marks[0][i]>4){
            c++;
        }
        else
            if(marks[0][i]!=marks[1][i] )
                c++;

    }
    printf("%d",c);

    return 0;
}


#include <stdio.h>

int main(void) {
    int n, m,tmp=0,c=0;
    scanf("%d%d",&n,&m);
    int marks[101][101];

    for(int i=0 ;i<n ;i++){
        for(int j=0 ;j<m ;j++){
            scanf("%d",&marks[i][j]);
        }
    }

    for(int i=0 ;i<m ;i++){
        for(int j=0 ;j<n ;j++){
            if(marks[j][i]<marks[j+1][i]){
            tmp=marks[j][i];
            marks[j][i]=marks[j+1][i];
            marks[j+1][i]=tmp;
            }
        }
    }

    for(int i=0 ;i<m ; i++){
        if(marks[0][i]>4){
            c++;
        }
        else
            if(marks[0][i]!=marks[1][i])
                c++;

    }
    printf("%d",c);

    return 0;
}


#include <stdio.h>

int main(void) {
    int n, m,tmp=0,c=0;
    scanf("%d%d",&n,&m);
    int marks[100][100]={0};

    for(int i=0 ;i<n ;i++){
        for(int j=0 ;j<m ;j++){
            scanf("%d",&marks[i][j]);
        }
    }

    for(int i=0 ;i<m ;i++){
        for(int j=0 ;j<n ;j++){
            if(marks[j][i]<marks[j+1][i]){
            tmp=marks[j][i];
            marks[j][i]=marks[j+1][i];
            marks[j+1][i]=tmp;
            }
        }
    }

    for(int i=0 ;i<m ; i++){
        if(marks[0][i]>4){
            c++;
        }
        else
            if(marks[0][i]!=marks[1][i] )
                c++;

    }
    printf("%d\n",c);

    return 0;
}


#include <stdio.h>
int main(void) {
    int n, m,tmp=0,c=0;
    scanf("%d%d",&n,&m);
    char marks[101][101];

    for(int i=0 ;i<n ;i++){
        for(int j=0 ;j<m ;j++){
            scanf(" %c",&marks[i][j]);
            marks[i][j]-='0';
        }
    }

    for(int i=0 ;i<m ;i++){
        for(int j=0 ;j<n ;j++){
            if(marks[j][i]<marks[j+1][i]){
            tmp=marks[j][i];
            marks[j][i]=marks[j+1][i];
            marks[j+1][i]=tmp;
            }
        }
    }

    for(int i=0 ;i<m ; i++){
        if(marks[0][i]>4){
            c++;
        }
        else
            if(marks[0][i]!=marks[1][i])
                c++;

    }
    printf("%d",c);

    return 0;
}


#include <stdio.h>

int main(void) {
    int n, m,tmpl=0,c=0;
    scanf("%d%d",&n,&m);
    int marks[100][100]={0};

    for(int i=0 ;i<n ;i++){
        for(int j=0 ;j<m ;j++){
            scanf_s("%d",&marks[i][j]);
        }
    }

    for(int i=0 ;i<m ;i++){
        for(int j=0 ;j<n ;j++){
            if(marks[j][i]<marks[j+1][i]){
            tmpl=marks[j][i];
            marks[j][i]=marks[j+1][i];
            marks[j+1][i]=tmpl;
            }
        }
    }

    for(int i=0 ;i<m ; i++){
        if(marks[0][i]>4){
            c++;
        }
        else
            if(marks[0][i]!=marks[1][i] )
                c++;

    }
    printf("%d\n",c);

    return 0;
}


#include <stdio.h>

int main(void) {
    int n, m,tmp=0,c=0;
    scanf("%d%d",&n,&m);
    int marks[100][100]={0};

    for(int i=0 ;i<n ;i++){
        for(int j=0 ;j<m ;j++){
            scanf("%d",&marks[i][j]);
        }
    }

    for(int i=0 ;i<m ;i++){
        for(int j=0 ;j<n ;j++){
            if(marks[j][i]<marks[j+1][i]){
            tmp=marks[j][i];
            marks[j][i]=marks[j+1][i];
            marks[j+1][i]=tmp;
            }
        }
    }

    for(int i=0 ;i<m ; i++){
        if(marks[0][i]>4){
            c++;
        }
        else
            if(marks[0][i]!=marks[1][i] )
                c++;

    }
    printf("%d",c);

    return 0;
}


#include <iostream>
using namespace std;

int main() {

    int n ,m;
    cin>>n>>m;
    string a[100];
    int b[100][100];
    int j=0;
    for(int i=0 ;i<n ;i++){
        cin>>a[i];
    }
    char max='0';
    int ans=0;

    for (int i = 0; i < n; ++i){
    bool wasBest = false;
    for(int j = 0; j < m; ++j){
        bool isBest = true;
        for(int k = 0; k < n; ++k)
            if(a[k][j] > a[i][j])
                isBest = false;
        if(isBest)
            wasBest = true;
    }
    if(wasBest)
        ans++;
    }

    cout<<ans;
    return 0;
}


#include <iostream>
#include "vector"
#include "bits/stdc++.h"
using namespace std;

int main()
{
   int stu ,sub,c=0;
   char arr[100][100] ;
   cin>>stu>>sub;
   bool ar[stu];
   for(int i=1;i<=stu;i++)
     for(int j=1;j<=sub;j++)
     cin>>arr[i][j];
   for(int i=1;i<=stu;i++)
     for(int j=1;j<=sub;j++)
    if(arr[j][i]-48==(*max_element((arr[i]),arr[i]+stu))-48)
           ar[i]=1;
    for(int j=1;j<=stu;j++)
    if(ar[j]==1)
         c++;
    cout<<c<<endl;

    return 0;
}


#include <iostream>
#include "bits/stdc++.h"
using namespace std;
 int stu ,sub;
//char maxVal ((&arr)[100][100])
int main()
{
  int c=0, stu,sub;
   char arr[100][100] ;
   cin>>stu>>sub;
   bool ar[100]={0};
   for(int i=1;i<=stu;i++)
     for(int j=1;j<=sub;j++)
     cin>>arr[i][j];
   for(int i=1;i<=sub;i++)
    {
        char val=0;
        for(int s=1;s<=stu;s++)
            if(arr[s][i]>val)
            val=arr[s][i];
     for(int j=1;j<=stu;j++)
    if(arr[j][i]==val)
           ar[j]=1;
    }
    for(int j=1;j<=sub;j++)
    if(ar[j-1]==1)
         c++;
    cout<<c<<endl;

    return 0;
}


#include <iostream>
#include "vector"
#include "bits/stdc++.h"
using namespace std;

int main()
{
   int stu ,sub,c=0;
   char arr[100][100] ;
   cin>>stu>>sub;
   bool ar[stu];
   for(int i=1;i<=stu;i++)
     for(int j=1;j<=sub;j++)
     cin>>arr[i][j];
   for(int i=1;i<=stu;i++)
     for(int j=1;j<=sub;j++)
    if(arr[j][i]==(*max_element((arr[i]),arr[i]+stu)))
           ar[i]=1;
    for(int j=1;j<=stu;j++)
    if(ar[j]==1)
         c++;
    cout<<c<<endl;

    return 0;
}


#include <iostream>
#include "vector"
#include "bits/stdc++.h"
using namespace std;

int main()
{
   int stu ,sub,c=0;
    int myints[] = {3,7,2,5,6,8,8};
   char arr[100][100] ;
   cin>>stu>>sub;
   bool ar[stu];

   for(int i=1;i<=stu;i++)
     for(int j=1;j<=sub;j++)
     cin>>arr[i][j];
   for(int i=1;i<=stu;i++)
     for(int j=1;j<=sub;j++)
    if(arr[j][i]-48==(*max_element((arr[i]),arr[i]+stu))-48)
       {

           ar[i]=1;
       }

    for(int j=1;j<=stu;j++)
    if(ar[j]==1)
         c++;
    cout<<c<<endl;

    return 0;
}


#include <iostream>
#include "bits/stdc++.h"
using namespace std;
 int stu ,sub;
//char maxVal ((&arr)[100][100])
int main()
{
  int c, stu,sub;
   char arr[100][100] ;
   cin>>stu>>sub;
   bool ar[100]={0};
   for(int i=1;i<=stu;i++)
     for(int j=1;j<=sub;j++)
     cin>>arr[i][j];
   for(int i=1;i<=sub;i++)
    {
        char val=0;
        for(int s=1;s<=stu;s++)
            if(arr[s][i]>val)
            val=arr[s][i];
     for(int j=1;j<=stu;j++)
    if(arr[j][i]==val)
           ar[j]=1;
    }
    c=0;
    for(int j=1;j<=stu;j++)
    if(ar[j]==1)
         c++;
    cout<<c<<endl;

    return 0;
}


#include <iostream>
#include "bits/stdc++.h"
using namespace std;
 int stu ,sub;
//char maxVal ((&arr)[100][100])
int main()
{
  int c=0, stu,sub;
   char arr[100][100] ;
   cin>>stu>>sub;
   bool ar[100]={0};
   for(int i=1;i<=stu;i++)
     for(int j=1;j<=sub;j++)
     cin>>arr[i][j];
   for(int i=1;i<=sub;i++)
    {
        char val=0;
        for(int s=1;s<=stu;s++)
            if(arr[s][i]>val)
            val=arr[s][i];
     for(int j=1;j<=stu;j++)
    if(arr[j][i]==val)
           ar[j]=1;
    }
    for(int j=1;j<=stu;j++)
    if(ar[j]==1)
         c++;
    cout<<c<<endl;

    return 0;
}


#include <iostream>
#include "bits/stdc++.h"
using namespace std;
 int stu ,sub;
//char maxVal ((&arr)[100][100])
int main()
{
  int c=0, stu,sub;
   char arr[100][100] ;
   cin>>stu>>sub;
   bool ar[100]={0};
   for(int i=1;i<=stu;i++)
     for(int j=1;j<=sub;j++)
     cin>>arr[i][j];
   for(int i=1;i<=sub;i++)
    {
        char val=0;
        for(int s=1;s<=stu;s++)
            if(arr[s][i]>val)
            val=arr[s][i];
     for(int j=1;j<=stu;j++)
    if(arr[j][i]==val)
           ar[j]=1;
    }
    for(int j=1;j<=sub;j++)
    if(ar[j]==1)
         c++;
    cout<<c<<endl;

    return 0;
}


#include <iostream>
#include "bits/stdc++.h"
using namespace std;
 int stu ,sub;
//char maxVal ((&arr)[100][100])
int main()
{
  int c, stu,sub;
   char arr[101][101] ;
   cin>>stu>>sub;
   bool ar[101]={0};
   for(int i=1;i<=stu;i++)
     for(int j=1;j<=sub;j++)
     cin>>arr[i][j];
   for(int i=1;i<=sub;i++)
    {
        char val=0;
        for(int s=1;s<=stu;s++)
            if(arr[s][i]>val)
            val=arr[s][i];
     for(int j=1;j<=stu;j++)
    if(arr[j][i]==val)
           ar[j]=1;
    }
    c=0;
    for(int j=1;j<=stu;j++)
    if(ar[j]==1)
         c++;
    cout<<c<<endl;

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    vector<int> v;
    bool vb = 1;
    vector<bool> scf;
    int n,m,x,noss=0,ctr=0;
    cin >> n >> m;
    for(int i = 0;i<n;i++){
        cin >> x;
        v.push_back(x);
        scf.push_back(0);
    }
    for(int iii =0;iii<m;iii++){
        for(int i = 0;i<n;i++){
            for(int ii = 0;ii<n;ii++){
                ctr ++;
                if(v[i]%10<v[ii]%10){
                vb = 0;
                }
            }
            if(vb==1){
            scf[i]=1;
            }
        }
        for(int newv = 0;newv<n;newv++){
        v[newv] /= 10;
        }
        vb=1;
    }
    for(int i = 0;i<n;i++){
        if(scf[i]==1){
        noss ++;
        }
    }
    cout << noss ;
    //system("pause");
    return 0;
    }


#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    vector<int> v;
    vector<bool> vb;
    vector<bool> scf;
    int n,m,x,noss=0,ctr=0;
    cin >> n >> m;
    for(int i = 0;i<n;i++){
        cin >> x;
        v.push_back(x);
        vb.push_back(1);
        scf.push_back(0);
    }
    for(int iii =0;iii<m;iii++){
        for(int i = 0;i<n;i++){
            for(int ii = 0;ii<n;ii++){
                if(v[i]%10<v[ii]%10){
                vb[i] = 0;
                break;
                }
            }
            if(vb[i]==1){
            scf[i]=1;
            }
        }
        for(int newv = 0;newv<n;newv++){
        v[newv] /= 10;
        vb[newv] =1;
        }
    }
    for(int i = 0;i<n;i++){
        if(scf[i]==1){
        noss ++;
        }
    }
    cout << noss;
    //system("pause");
    return 0;
    }


#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    vector<vector<char> > s;
    vector<char> g;
    vector<bool> ss;
    bool vb = 1;
    int n,m,noss = 0;
    char x;
    cin >> n >> m;
    for(int i = 0;i<n;i++){
        for(int ii = 0;ii<m;ii++){
        cin >> x;
        g.push_back(x);
        }
    ss.push_back(0);
    s.push_back(g);
    g.clear();
    }
    for(int iii=0;iii<m;iii++){
        for(int ii =0;ii<n;ii++){
            vb =1;
            for(int i = 0;i<n;i++){
                if(s[ii][iii]<s[i][iii]){
                vb=0;
                }
                if(i==n-1){
                    if(vb == 1){
                    ss[ii] = 1;
                    }
                }
            }
        }
    }
    for(int i = 0;i<n;i++){
        if(ss[i]==1){
        noss++;
        }
    }
    cout << noss;
    //system("pause");
    return 0;
    }


#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    vector<long long int> v;
    bool vb ;
    vector<bool> scf;
    long int n,m,x,noss=0,ctr=0;
    cin >> n >> m;
    for(long long int i = 0;i<n;i++){
        cin >> x;
        v.push_back(x);
        scf.push_back(0);
    }
    for(long long int iii =0;iii<m;iii++){
        for(long long int i = 0;i<n;i++){
            vb = 1;
            for(long long int ii = 0;ii<n;ii++){
                ctr ++;
                if(v[i]%10<v[ii]%10){
                vb = 0;
                }
            }
            if(vb==1){
            scf[i]=1;
            }
        }
        for(long long int newv = 0;newv<n;newv++){
        v[newv] /= 10;
        }
    }
    for(long long int i = 0;i<n;i++){
        if(scf[i]==1){
        noss ++;
        }
    }
    cout << noss ;
    //system("pause");
    return 0;
    }


#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    vector<int> v;
    vector<bool> vb;
    vector<bool> scf;
    int n,m,x,noss=0,ctr=0;
    cin >> n >> m;
    for(int i = 0;i<n;i++){
        cin >> x;
        v.push_back(x);
        vb.push_back(1);
        scf.push_back(0);
    }
    for(int iii =0;iii<m;iii++){
        for(int i = 0;i<n;i++){
            for(int ii = 0;ii<n;ii++){
                ctr ++;
                if(v[i]%10<v[ii]%10){
                vb[i] = 0;
                }
            }
            if(vb[i]==1){
            scf[i]=1;
            }
        }
        for(int newv = 0;newv<n;newv++){
        v[newv] /= 10;
        vb[newv] =1;
        }
    }
    for(int i = 0;i<n;i++){
        if(scf[i]==1){
        noss ++;
        }
    }
    cout << noss ;
    //system("pause");
    return 0;
    }


#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    vector<int> v;
    vector<bool> vb;
    vector<bool> scf;
    int n,m,x,noss=0,ctr=0;
    cin >> n >> m;
    for(int i = 0;i<n;i++){
        cin >> x;
        v.push_back(x);
        vb.push_back(1);
        scf.push_back(0);
    }
    for(int iii =0;iii<m;iii++){
        for(int i = 0;i<n;i++){
            for(int ii = 0;ii<n;ii++){
                ctr ++;
                if(v[i]%10<v[ii]%10){
                vb[i] = 0;
                }
            }
            if(vb[i]==1){
            scf[i]=1;
            }
        }
        for(int newv = 0;newv<n;newv++){
        v[newv] /= 10;
        vb[newv] =1;
        }
    }
    for(int i = 0;i<n;i++){
        if(scf[i]==1){
        noss ++;
        }
    }
    cout << noss << endl << ctr << endl;
    //system("pause");
    return 0;
    }


#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    vector<long int> v;
    bool vb ;
    vector<bool> scf;
    int n,m,x,noss=0,ctr=0;
    cin >> n >> m;
    for(long int i = 0;i<n;i++){
        cin >> x;
        v.push_back(x);
        scf.push_back(0);
    }
    for(long int iii =0;iii<m;iii++){
        for(long int i = 0;i<n;i++){
            vb = 1;
            for(long int ii = 0;ii<n;ii++){
                ctr ++;
                if(v[i]%10<v[ii]%10){
                vb = 0;
                }
            }
            if(vb==1){
            scf[i]=1;
            }
        }
        for(long int newv = 0;newv<n;newv++){
        v[newv] /= 10;
        }
    }
    for(long int i = 0;i<n;i++){
        if(scf[i]==1){
        noss ++;
        }
    }
    cout << noss ;
    //system("pause");
    return 0;
    }


#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    vector<int> v;
    bool vb = 1;
    vector<bool> scf;
    int n,m,x,noss=0,ctr=0;
    cin >> n >> m;
    for(int i = 0;i<n;i++){
        cin >> x;
        v.push_back(x);
        scf.push_back(0);
    }
    for(int iii =0;iii<m;iii++){
        for(int i = 0;i<n;i++){
            vb=1;
            for(int ii = 0;ii<n;ii++){
                ctr ++;
                if(v[i]%10<v[ii]%10){
                vb = 0;
                }
            }
            if(vb==1){
            scf[i]=1;
            }
        }
        for(int newv = 0;newv<n;newv++){
        v[newv] /= 10;
        }
    }
    for(int i = 0;i<n;i++){
        if(scf[i]==1){
        noss ++;
        }
    }
    cout << noss ;
    //system("pause");
    return 0;
    }


#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    vector<long long int> v;
    bool vb ;
    vector<bool> scf;
    long long int n,m,x,noss=0,ctr=0;
    cin >> n >> m;
    for(long long int i = 0;i<n;i++){
        cin >> x;
        v.push_back(x);
        scf.push_back(0);
    }
    for(long long int iii =0;iii<m;iii++){
        for(long long int i = 0;i<n;i++){
            vb = 1;
            for(long long int ii = 0;ii<n;ii++){
                ctr ++;
                if(v[i]%10<v[ii]%10){
                vb = 0;
                }
            }
            if(vb==1){
            scf[i]=1;
            }
        }
        for(long long int newv = 0;newv<n;newv++){
        v[newv] /= 10;
        }
    }
    for(long long int i = 0;i<n;i++){
        if(scf[i]==1){
        noss ++;
        }
    }
    cout << noss ;
    //system("pause");
    return 0;
    }


#include <iostream>
using namespace std;

int main() {

int rows,cols;
cin>>rows>>cols;

string x[1000];
for(int i=0;i<rows;i++)
cin>>x[i];
int max[1000];
for(int i=0;i<1000;i++)
max[i]=0;

for(int i=0;i<cols;i++)
{
	for(int j=0;j<rows;j++)
	{
		if(max[i]<x[j][i]-'0')
		{
			max[i]=x[j][i]-'0';
		}
	}
}
bool taken[1000];
for(int i=0;i<1000;i++)
taken[i]=false;

for(int i=0;i<cols;i++)
{
	for(int j=0;j<rows;j++)
	{
		if(max[i]==x[j][i]-'0')
		{
			taken[j]=true;
		//	cout<<"Max:"<<max[j]<<endl;

		}
	}
}
int count=0;
for(int i=0;i<1000;i++)
if(taken[i])
count++;
cout<<count<<endl;
return 0;
}


#include <iostream>
using namespace std;

int main() {

int rows,cols;
cin>>rows>>cols;

string x[1000];
for(int i=0;i<rows;i++)
cin>>x[i];
int max[1000];
for(int i=0;i<1000;i++)
max[i]=0;

for(int i=0;i<cols;i++)
{
	for(int j=0;j<rows;j++)
	{
		if(max[i]<=x[i][j]-'0')
		{
			max[i]=x[i][j]-'0';
		}
	}
}
bool taken[1000];
for(int i=0;i<1000;i++)
taken[i]=false;

for(int i=0;i<cols;i++)
{
	for(int j=0;j<rows;j++)
	{
		if(max[j]==x[j][i]-'0')
		{
			taken[j]=true;
		//	cout<<"Max:"<<max[j]<<endl;
			break;

		}
	}
}
int count=0;
for(int i=0;i<1000;i++)
if(taken[i])
count++;
cout<<count<<endl;
return 0;
}


#include <iostream>
using namespace std;

int main() {

int  max[101];

for(int i=0;i<101;i++)
max[i]=0;

int x,y;
cin>>x>>y;

string t[101];

for(int i=0;i<x;i++)
{
	cin>>t[i];
}
int ch[1000];
for(int i=0;i<1000;i++)
ch[i]=0;

for(int i=0;i<y;i++)
{
	for(int j=0;j<x;j++)
	{
		if(t[j][i]-'0'>max[i])
		{
		max[j]=t[j][i]-'0';
	//	cout<<max[j]<<endl;
		}

	}
}
int count=0;
bool taken[1000];
for(int i=0;i<1000;i++)
taken[i]=false;
for(int i=0;i<y;i++)
{
	for(int j=0;j<x;j++)
	{
		if(t[j][i]-'0'==max[j])
		{
		taken[j]=true;
		break;
		}
	}
}
for(int i=0;i<1000;i++)
if(taken[i])
count++;
cout<<count<<endl;

return 0;
}


#include <iostream>
using namespace std;

int main() {
	char h[1000][1000];

	int x,y;
	cin>>x>>y;

	for(int i=0;i<x;i++)
	{
		for(int j=0;j<y;j++)
		cin>>h[i][j];

	}

	int max=0;
	int count=0;

	for(int j=0;j<y;j++)
	{
	max=0;
	int ch=0;
		for(int i=0;i<x;i++)
		{

			if(h[i][j]-'0'>max)
			{
			    if(max!=0)
			    count--;
				max=h[i][j]-'0';
				count++;
				ch=0;
			}
			else if(h[i][j]-'0'==max)
			{
				if(ch==0)
				count--;
				ch++;
			}
			if(ch==x-1)
			count++;
		//	if(i==x-1)
		//	count-=ch;

		//	if(i==x-2)
		//	count++;
		}
	}
	cout<<count<<endl;
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	char h[1000][1000];

	int x,y;
	cin>>x>>y;

	for(int i=0;i<x;i++)
	{
		for(int j=0;j<y;j++)
		cin>>h[i][j];
	}
	int max=0;

	int count=0;

	for(int j=0;j<y;j++)
	{
	max=0;
		for(int i=0;i<x;i++)
		{
			if(h[i][j]-'0'>max)
			{
				max=h[i][j]-'0';
			}
			else if(h[i][j]-'0'==max)
			{
				count--;
				break;
			}
			if(i<x-2)
			count++;

		}
	}
	cout<<count<<endl;
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	char h[1000][1000];

	int x,y;
	cin>>x>>y;

	for(int i=0;i<x;i++)
	{
		for(int j=0;j<y;j++)
		cin>>h[i][j];

	}

	int max=0;
	int count=0;
	int s[1000];
	for(int i=0;i<1000;i++)
	s[i]=0;

	for(int j=0;j<y;j++)
	{

	max=0;
	int ch=0;

		for(int i=0;i<x;i++)
		{

			if(h[i][j]-'0'>max)
			{
			    if(max!=0)
			    count--;
				max=h[i][j]-'0';
				count++;
				ch=0;
				if(s[i]==0)
				s[i]=1;
			}
			else if(h[i][j]-'0'==max)
			{
				if(ch==0)
				count--;
				ch++;
			}
			if(ch==x-1)
			{
			count++;
			s[101]=1;
			}
		//	if(i==x-1)
		//	count-=ch;

		//	if(i==x-2)
		//	count++;
		}
	}
int	sum=0;
	for(int i=0;i<1000;i++)
	sum+=s[i];
	cout<<sum<<endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,m,c=0;
    char a[110][110];
    cin>>n>>m;
    for(int i=0;i<n;i++)
            cin>>a[i];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
             int t=0;
            for(int k=0;k<n;k++)
            {
                if((i!=k)&&(a[i][j]>=a[k][j]))
                {
                    t++;
                }

            }
            if(t==n-1)
            {
                c++;
                i++;
                j=0;
            }
        }

    }
    if(n==1)
        cout<<1;
    else
        cout<<c;
    return 0;

}


#include<iostream>
using namespace std;
int main()
{
    int n,m,a[110][110],c=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
            cin>>a[i];
    for (int i = 0; i < n; ++i){
    bool wasBest = false;
    for(int j = 0; j < m; ++j){
        bool isBest = true;
        for(int k = 0; k < n; ++k)
            if(a[k][j] > a[i][j])
                isBest = false;
        if(isBest)
            wasBest = true;
    }
    if(wasBest)
        c++;
}

    cout<<c;
    return 0;

}


#include<iostream>
using namespace std;
int main()
{
    int n,m,c=0;
    char a[110][110];
    cin>>n>>m;
    for(int i=0;i<n;i++)
            cin>>a[i];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
             int t=0;
            for(int k=0;k<n;k++)
            {
                if((i!=k)&&(a[i][j]>=a[k][j]))
                {
                    t++;
                }

            }
            if(t==n-1)
            {
                c++;
                i++;
                j=0;
            }
        }

    }

    cout<<c;
    return 0;

}


#include<iostream>
using namespace std;
int main()
{
    int n,m,a[110][110],c=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>a[i][j];
    for (int i = 0; i < n; ++i){
    bool wasBest = false;
    for(int j = 0; j < m; ++j){
        bool isBest = true;
        for(int k = 0; k < n; ++k)
            if(a[k][j] > a[i][j])
                isBest = false;
        if(isBest)
            wasBest = true;
    }
    if(wasBest)
        c++;
}

    cout<<c;
    return 0;

}


#include<iostream>
using namespace std;
int main()
{
    int n,m,a[110][110],c=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>a[i][j];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
             int t=0;
            for(int k=0;k<n;k++)
            {
                if((i!=k)&&(a[i][j]>=a[k][j]))
                {
                    t++;
                }

            }
            if(t==n-1)
            {
                c++;
                i++;
                j=0;
            }
        }

    }

    cout<<c;
    return 0;

}


#include<iostream>
using namespace std;
int main()
{
    int n,m,c=0;
    char a[110][110];
    cin>>n>>m;
    for(int i=0;i<n;i++)
            cin>>a[i];

    for (int i = 0; i < n; ++i){
    bool wasBest = false;
    for(int j = 0; j < m; ++j){
        bool isBest = true;
        for(int k = 0; k < n; ++k)
            if(a[k][j] > a[i][j])
                isBest = false;
        if(isBest)
            wasBest = true;
    }
    if(wasBest)
        c++;
}

    cout<<c;
    return 0;

}


#include<iostream>
using namespace std;
int main()
{
    int n,m,a[100][100],c=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>a[i][j];
    for(int i=0;i<n;i++)
    {
        int t=0;
        for(int j=0;j<m;j++)
        {
            for(int k=0;k<n;k++)
            {
                if((i!=k)&&(a[i][j]>=a[k][j]))
                {
                    t++;
                }

            }
        }
        if(t>0)
            c++;
    }

    cout<<c;
    return 0;

}


#include<iostream>
#include<string>
#include<vector>
using namespace std;
int maine()
{
int n,m;
cin>>n>>m;
string temp="";
vector<string>str(n);
for(int i=0;i<n;i++)
{
sin>>temp;
str.push_back(temp);
}
string max=str[0];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(str[i][j]>max[j])
{
max[j]=str[i][j];
}}}
int count=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(str[i][j]==max[j])
count++;
cout<<count<<endl;
return 0;
}


#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
string temp="";
vector<string>str(n);
for(int i=0;i<n;i++)
{
cin>>temp;
str.push_back(temp);
}
string max=str[0];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(str[i][j]>max[j])
{
max[j]=str[i][j];
}}}
int count=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(str[i][j]>=max[j])
{
count++;
break;
}
cout<<count<<endl;
return 0;
}


#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
string temp="";
vector<string>str(n);
for(int i=0;i<n;i++)
{
cin>>temp;
str.push_back(temp);
}
string max=str[0];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(str[i][j]>max[j])
{
max[j]=str[i][j];
}}}
int count=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(str[i][j]==max[j])
count++;
cout<<count<<endl;
return 0;
}


#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
string temp="";
vector<string>str(n);
for(int i=0;i<n;i++)
{
cin>>temp;
str.push_back(temp);
}
string max=str[0];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(str[i][j]>max[j])
{
max[j]=str[i][j];
}}}
int count=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(str[i][j]>=max[j])
count++;
cout<<count<<endl;
return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main ()
{
    int n , m ;
    string max;
    string temp;
    cin >> n >> m;
    vector <string> str;
    for (int i =0 ; i <n ; i++) {
    cin >> temp;
     str.push_back(temp); }
    max = str[n-1];

    for (int i =0 ; i <n-1 ; i++)
    {
        for (int j =0 ; j < m ; j++)
        {
            if (str[i][j]>max[j]) max[j]=str[i][j];
        }
    }

    int cnt = 0;

    for (int i = 0 ; i < n ; i++)
    {
        for (int j =0 ; j < m ; j++)
        {
            if (str[i][j]>=max[j]) {
            cnt++ ;
             break;
             }
        }
    }
cout << cnt;
return 0;
}


#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
string temp="";
vector<string>str(n);
for(int i=0;i<n;i++)
{
cin>>temp;
str.push_back(temp);
}
string max=str[0];
for(int i=1;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(str[i][j]>max[j])
{
max[j]=str[i][j];
}}}
int count=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(str[i][j]==max[j])
{
count++;
break;
}
cout<<count<<endl;
return 0;
}


#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
string temp="";
vector<string>str(n);
for(int i=0;i<n;i++)
{
cin>>temp;
str.push_back(temp);
}
string max=str[0];
for(int i=1;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(str[i][j]>max[j])
{
max[j]=str[i][j];
}}}
int cnt = 0;

    for (int i = 0 ; i < n ; i++)
    {
        for (int j =0 ; j < m ; j++)
        {
            if (s[i][j]>=max[j]) {cnt++ ; break;}
        }
    }
cout << cnt;
return 0;
}


#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
string temp="";
vector<string>str(n);
for(int i=0;i<n;i++)
{
cin>>temp;
str.push_back(temp);
}
string max=str[0];
for(int i=1;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(str[i][j]>max[j])
{
max[j]=str[i][j];
}}}
int cnt = 0;

    for (int i = 0 ; i < n ; i++)
    {
        for (int j =0 ; j < m ; j++)
        {
            if (str[i][j]>=max[j]) {cnt++ ; break;}
        }
    }
cout << cnt;
return 0;
}


 #include <iostream>
#include <vector>
#include <string>
using namespace std;

int main ()
{
    int n , m ;
    string max;
    string temp;
    cin >> n >> m;
    vector <string> str;
    for (int i =0 ; i <n ; i++) {
    cin >> temp;
     str.push_back(temp); }
    max = str[n-1];

    for (int i =0 ; i <n-1 ; i++)
    {
        for (int j =0 ; j < m ; j++)
        {
            if (str[i][j]>max[j]) max[j]=str[i][j];
        }
    }

    int cnt = 0;

    for (int i = 0 ; i < n ; i++)
    {
        for (int j =0 ; j < m ; j++)
        {
            if (str[i][j]>=max[j]) {
            cnt++ ;
             break;
             }
        }
    }
cout << cnt;
return 0;
}


#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    int num,m,x=0;
    cin>>num>>m;
    int arr1[m],count[m];
    string arr[num];
    for(int i=0;i<num;i++)
    {
    cin>>arr[i];}
    int min=0;
    for(int n=0;n<m;n++)
    {
             arr1[n]=0;
    for(int j=0;j<num;j++)
    {
    //cout<<arr[j][n]<<endl;
    if((int(arr[j][n])-48)>arr1[n])
    {
    arr1[n]=int(arr[j][n])-48;
    count[n]=j;

        }}

}
/*for(int k=0;k<m;k++)
{
cout<<count[k];}*/
int count1=0;
for(int l=0;l<m;l++)
        {
          count1++;
        for (int k = l+1; k < m; k++){
            if(count[l]==count[k])
            {
                              min=count[l+1];
                              count[k]==count[l+1];
                              l+=2;
                              }}
                        }

            cout<<count1;

    return 0;
}


#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
string temp="";
vector<string>str(n);
for(int i=0;i<n;i++)
{
cin>>temp;
str.push_back(temp);
}
string max=str[n-1];
for(int i=1;i<n-1;i++)
{
for(int j=0;j<m;j++)
{
if(str[i][j]>max[j])
{
max[j]=str[i][j];
}}}
int cnt = 0;

    for (int i = 0 ; i < n ; i++)
    {
        for (int j =0 ; j < m ; j++)
        {
            if (str[i][j]>=max[j]) {cnt++ ; break;}
        }
    }
cout << cnt;
return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main ()
{
    int n , m ;
    string max;
    string temp;
    cin >> n >> m;
    vector <string> str;
    for (int i =0 ; i <n ; i++) {
    cin >> temp;
     str.push_back(temp); }
    max = s[n-1];

    for (int i =0 ; i <n-1 ; i++)
    {
        for (int j =0 ; j < m ; j++)
        {
            if (str[i][j]>max[j]) max[j]=str[i][j];
        }
    }

    int cnt = 0;

    for (int i = 0 ; i < n ; i++)
    {
        for (int j =0 ; j < m ; j++)
        {
            if (str[i][j]>=max[j]) {
            cnt++ ;
             break;
             }
        }
    }
cout << cnt;
return 0;
}


#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    int n,m,count=0;
    string num;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
                    cin>>num;
                    for(int j=0;j<m;j++)
                    {
                    count=count+(int(num[i])-48);
                    }}
                    cout<<count/(n*m)<<endl;
                    return 0;
                    }


#include<iostream>
#include<string>
#include<vector>
using namespace std;
int maine()
{
int n,m;
cin>>n>>m;
string temp="";
vector<string>str(n);
for(int i=0;i<n;i++)
{
cin>>temp;
str.push_back(temp);
}
string max=str[0];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(str[i][j]>max[j])
{
max[j]=str[i][j];
}}}
int count=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(str[i][j]==max[j])
count++;
cout<<count<<endl;
return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str;
	int deg[150][150],max[150],n,m,y=-100,pass=0,x=0,xxx,num=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>str;
		for(int j=0;j<m;j++)
		{
			x=str[j];
			deg[i][j]=x-48;
			}
		}

	for(int r=0;r<m;r++)
	{
		for(int q=0;q<n;q++)
		{
			xxx=deg[q][r];
			if(xxx>y)
			{
				max[r]=xxx;

				}

			}
		}

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(deg[i][j]==max[j])
			{
				num+=1;
				break;

				}

			}
		if(num>=1)
		{
			pass+=1;
			}

			num=0;
		}

	cout<<pass<<endl;

	return 0;
}


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

using namespace std;
int main()
{
	int n,m,p=0;

	string r="";

	cin>>n>>m;
	vector<string> a(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		for(int j=0;j<m;j++)
		{
			if(a[i][j]>r[j])r[j]=a[i][j];

			}

		}
/*
	for(int i=0;i<n;i++)
	{
		cout<<a[i];
		}
	*/
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{

			if(a[i][j]==r[j])
				{
					p+=1;
					break;

					}
			}

		}
		cout<<p<<endl;

	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str;
	int deg[150][150],max[150],n,m,y=-100,pass=0,x=0,xxx,num=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>str;
		for(int j=0;j<m;j++)
		{
			x=str[j];
			deg[i][j]=x-48;
			}
		}

	for(int r=0;r<m;r++)
	{
		for(int q=0;q<n;q++)
		{
			xxx=deg[q][r];
			if(xxx>y)
			{
				max[r]=xxx;

				}

			}
		}

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(deg[i][j]==max[j])
			{
				num+=1;

				}

			}
		if(num>=1)
		{
			pass+=1;
			}

			num=0;
		}

	cout<<pass<<endl;

	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str;
	int deg[150][150],max[150],n,m,y=-100,pass=0,x=0,xxx,num=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>str;
		for(int j=0;j<m;j++)
		{
			x=str[j];
			deg[i][j]=x-48;
			}
		}

	for(int r=0;r<m;r++)
	{
		for(int q=0;q<n;q++)
		{
			xxx=deg[q][r];
			if(xxx>y)
			{
				max[r]=xxx;

				}

			}
		}

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(deg[i][j]==max[j])
			{
				num+=1;
				break;

				}

			}
		if(num>=1)
		{
			pass+=1;
			}
			num=0;
		}

	cout<<pass<<endl;

	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str;
    int deg[150][150],max[150],n,m,y=-100,pass=0,x=0,xxx,num=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>str;
        for(int j=0;j<m;j++)
        {
            x=str[j];
            deg[i][j]=x-48;
            }
        }

    for(int r=0;r<m;r++)
    {
        for(int q=0;q<n;q++)
        {
            xxx=deg[q][r];
            if(xxx>y)
            {
                max[r]=xxx;

                }

            }
        }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(deg[i][j]==max[j])
            {
                num+=1;
                break;

                }

            }
        if(num>=1)
        {
            pass+=1;
            }

            num=0;
        }

    cout<<pass<<endl;

    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str;
	int deg[150][150],max[150],n,m,y=-100,pass=0,x=0,xxx,num=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>str;
		for(int j=0;j<m;j++)
		{
			x=str[j];
			deg[i][j]=x-48;
			}
		}

	for(int r=0;r<m;r++)
	{
		y=-100;
		for(int q=0;q<n;q++)
		{
			xxx=deg[q][r];
			if(xxx>y)
			{
				max[r]=xxx;
				y=xxx;
				}

			}
		}

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(deg[i][j]==max[j])
			{
				num+=1;
				break;

				}

			}
		if(num>=1)
		{
			pass+=1;
			}

			num=0;
		}

	cout<<pass<<endl;

	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main ()
{
    int n,m,s=0;
    cin >>n >>m;
    char a[n][m];
    bool t[100];
    for (int i=0;i<100;i++)
    t[i]==false;
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        cin >>a[i][j];
    }
    int g=0;
    for (int i=0;i<m;i++)
    {
        for (int j=0;j<n;j++){
        if (a[j][i]>g) { g=a[j][i];}
        }

    for (int c=0;c<n;c++)
    if (a[c][i]==g && t[c]!=true) {s++;t[c]=true;}
    }

cout <<n-m;
}


#include <iostream>
#include <string>
using namespace std;
int main ()
{
    int n,m,s=0;
    cin >>n >>m;
    char a[n][m];
    bool t[100];
    for (int i=0;i<100;i++)
    t[i]=false;
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        cin >>a[i][j];
    }

    for (int i=0;i<m;i++)
    {
        int g=0;
        for (int j=0;j<n;j++){
        if (a[j][i]>g) { g=a[j][i];}
        }

    for (int c=0;c<n;c++)
    if (a[c][i]==g && t[c]!=true) {s++;t[c]=true;}
    }

cout <<s;


 #include <iostream>
#include <string>
using namespace std;
int main ()
{
    int n,m,s=0;
    cin >>n >>m;
    char a[n][m];
    bool t[100];
    for (int i=0;i<100;i++)
    t[i]=false;
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        cin >>a[i][j];
    }

    for (int i=0;i<m;i++)
    {
        int g=0;
        for (int j=0;j<n;j++){
        if (a[j][i]>g) { g=a[j][i];}
        }

    for (int c=0;c<n;c++)
    if (a[c][i]==g && t[c]!=true) {s++;t[c]=true;}
    }

cout <<s;
}


#include <iostream>
#include <string>
using namespace std;
int main ()
{
    int n,m,s=0;
    cin >>n >>m;
    char a[n][m];
    bool t[100];
    for (int i=0;i<100;i++)
    t[i]=false;
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        cin >>a[i][j];
    }
    int g=0;
    for (int i=0;i<m;i++)
    {
        for (int j=0;j<n;j++){
        if (a[j][i]>g) { g=a[j][i];}
        }

    for (int c=0;c<n;c++)
    if (a[c][i]==g && t[c]!=true) {s++;t[c]=true;}
    }

cout <<s;
}


#include <iostream>
#include <string>
using namespace std;
int main ()
{
    int n,m,s=0;
    cin >>n >>m;
    char a[n][m];
    bool t[100];
    for (int i=0;i<100;i++)
    t[i]=false;
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        cin >>a[i][j];
    }

    for (int i=0;i<m;i++)
    {
        int g=0;
        for (int j=0;j<n;j++){
        if (a[j][i]>g) { g=a[j][i];}
        }

    for (int c=0;c<n;c++)
    if (a[c][i]==g && t[c]!=true) {s++;t[c]=true;}
    }

cout <<s;
}


#include <iostream>
#include <string>
using namespace std;
int main ()
{
    int n,m,s=0;
    cin >>n >>m;
    char a[n][m];
    bool t[100];
    for (int i=0;i<100;i++)
    t[i]==false;
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        cin >>a[i][j];
    }
    int g=0;
    for (int i=0;i<m;i++)
    {
        for (int j=0;j<n;j++){
        if (a[j][i]>g) { g=a[j][i];}
        }

    for (int c=0;c<n;c++)
    if (a[c][i]==g && t[c]!=true) {s++;t[c]=true;}
    }

cout <<a[0][0];
}


#include <iostream>
#include <string>
using namespace std;
int main ()
{
    int n,m,s=0;
    cin >>n >>m;
    char a[n][m];
    bool t[100];
    for (int i=0;i<100;i++)
    t[i]==false;
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        cin >>a[i][j];
    }
    int g=0;
    for (int i=0;i<m;i++)
    {
        for (int j=0;j<n;j++){
        if (a[j][i]>g) { g=a[j][i];}
        }

    for (int c=0;c<n;c++)
    if (a[c][i]==g && t[c]!=true) {s++;t[c]=true;}
    }

cout <<s;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main ()
{
  int n,m,h,g=0;
  bool t;
  cin >>n >>m;
  short a[n][m];
  for (int i=0;i<n;i++)
  {
      for (int j=0;j<m;j++)
      cin >>a[i][j];
}
vector <int> b;
b.push_back(10);
for (int i=0;i<n;i++)
{
    for (int j=0;j<m;j++){
    if (a[i][j]>g) {g=a[i][j];h=j;}
    for (int c=0;c<b.size();c++){
    if (h!=j) {t=true;}
    else {t=false;break;}
    if (t==true) b.push_back(h);
}
}}
cout <<b.size();
}


#include <iostream>
#include <string>
using namespace std;
int main ()
{
    int n,m,s=0;
    cin >>n >>m;
    char a[n][m];
    bool t[100];
    for (int i=0;i<100;i++)
    t[i]==false;
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        cin >>a[i][j];
    }
    int g=0;
    for (int i=0;i<m;i++)
    {
        for (int j=0;j<n;j++){
        if (a[j][i]>g) { g=a[j][i];}
        }

    for (int c=0;c<n;c++)
    if (a[c][i]==g && t[c]!=true) {s++;t[c]=true;}
    }

cout <<a[0][1];
}


/*
  ID:
  PROG: transform
  LANG: C++
*/
#include <bits/stdc++.h>
using namespace std ;

int main(){
  int n , m , a[110][110] ;
  vector < int > v[110] ;
  cin >> n >> m ;
  for ( int i = 0 ; i < n ; i++ )
    for ( int j = 0 ; j < m ; j++ ){
      char c ;
      cin >> c ;
      a[i][j] = c - '0' ;
    }
  for ( int i = 0 ; i < m ; i++ ){
    int maxn = -1 ;
    for ( int j = 0 ; j < n ; j++ )
      maxn = max ( maxn , a[j][i] ) ;
    for ( int j = 0 ; j < n ; j++ )
      if ( a[j][i] == maxn ){
	v[j].push_back ( 1 ) ;
      }
  }
  int p = 0 ;
  for ( int i = 0 ; i < n ; i++ )
    if ( v[i].size() > 0 )
      p++ ;
  cout << p ;
  return 0 ;
}


/*
  ID:
  PROG: transform
  LANG: C++
*/
#include <bits/stdc++.h>
using namespace std ;

int main(){
  int n , m , a[110][110] ;
  vector < int > v[110] ;
  cin >> n >> m ;
  if ( m == 1 ){
    cout << 1 ;
    return 0 ;
  }
  for ( int i = 0 ; i < n ; i++ )
    for ( int j = 0 ; j < m ; j++ ){
      char c ;
      cin >> c ;
      a[i][j] = c - '0' ;
    }
  for ( int i = 0 ; i < m ; i++ ){
    int maxn = -1 ;
    for ( int j = 0 ; j < n ; j++ )
      maxn = max ( maxn , a[j][i] ) ;
    for ( int j = 0 ; j < n ; j++ )
      if ( a[j][i] == maxn ){
	v[j].push_back ( 1 ) ;
      }
  }
  int p = 0 ;
  for ( int i = 0 ; i < n ; i++ )
    if ( v[i].size() > 0 )
      p++ ;
  cout << p ;
  return 0 ;
}


/*
  ID:
  PROG: transform
  LANG: C++
*/
#include <bits/stdc++.h>
using namespace std ;

int main(){
  int n , m , a[110][110] ;
  vector < int > v[110] ;
  cin >> n >> m ;
  for ( int i = 0 ; i < n ; i++ )
    for ( int j = 0 ; j < m ; j++ ){
      char c ;
      cin >> c ;
      a[i][j] = c - '0' ;
    }
  for ( int i = 0 ; i < m ; i++ ){
    int maxn = -1 ;
    for ( int j = 0 ; j < n ; j++ )
      maxn = max ( maxn , a[j][i] ) ;
    for ( int j = 0 ; j < n ; j++ )
      if ( a[j][i] == maxn ){
	v[j].push_back ( 1 ) ;
      }
  }
  int maxx = 100000 , p = 0 ;
  for ( int i = 0 ; i < n ; i++ )
    if ( v[i].size() <= maxx && v[i].size() > 0 ) {
      maxx = v[i].size() ;
      p = i+1 ;
    }
  cout << p ;
  return 0 ;
}


/*
  ID:
  PROG: transform
  LANG: C++
*/
#include <bits/stdc++.h>
using namespace std ;

int main(){
  int n , m , a[110][110] ;
  vector < int > v[110] ;
  cin >> n >> m ;
  if ( m == 1 ){
    cout << 1 ;
    return 0 ;
  }
  for ( int i = 0 ; i < n ; i++ )
    for ( int j = 0 ; j < m ; j++ ){
      char c ;
      cin >> c ;
      a[i][j] = c - '0' ;
    }
  for ( int i = 0 ; i < m ; i++ ){
    int maxn = -1 ;
    for ( int j = 0 ; j < n ; j++ )
      maxn = max ( maxn , a[j][i] ) ;
    for ( int j = 0 ; j < n ; j++ )
      if ( a[j][i] == maxn ){
	v[j].push_back ( 1 ) ;
      }
  }
  int maxx = 100000 , p = 0 ;
  for ( int i = 0 ; i < n ; i++ )
    if ( v[i].size() <= maxx && v[i].size() > 0 ) {
      maxx = v[i].size() ;
      p = i+1 ;
    }
  cout << p ;
  return 0 ;
}


/*
  ID:
  PROG: transform
  LANG: C++
*/
#include <bits/stdc++.h>
using namespace std ;

int main(){
  int n , m , a[110][110] ;
  vector < int > v[110] ;
  cin >> n >> m ;
  for ( int i = 0 ; i < n ; i++ )
    for ( int j = 0 ; j < m ; j++ ){
      char c ;
      cin >> c ;
      a[i][j] = c - '0' ;
    }
  for ( int i = 0 ; i < m ; i++ ){
    int maxn = -1 ;
    for ( int j = 0 ; j < n ; j++ )
      maxn = max ( maxn , a[j][i] ) ;
    for ( int j = 0 ; j < n ; j++ )
      if ( a[j][i] == maxn ){
	v[j].push_back ( 1 ) ;
      }
  }
  int maxx = 0 , p = 0 ;
  for ( int i = 0 ; i < n ; i++ )
    if ( v[i].size() >= maxx ) {
      maxx = v[i].size() ;
      p = i+1 ;
    }
  cout << p ;
  return 0 ;
}


/*
  ID: hashemi4
  LANG: C++
  TASK: gift1
*/
// In the name of God
#include <algorithm>
#include <iostream>
#include <iterator>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <complex>
#include <cassert>
#include <cstdio>
#include <vector>
#include <bitset>
#include <string>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll>
//#define cin fin
//#define cout fout
typedef long long ll ;
typedef long double ld ;
using namespace std ;

int  main()
{
  ios_base::sync_with_stdio(false);
  int n , m ;
  cin >> n >> m ;
  string s[110] ;
  for ( int i = 0 ; i < n ; i++ )
    cin >> s[i] ;
  int maxn = 0 , q = 0 ;
  for ( int j = 0 ; j < n ; j++ )
    if ( s[j][0] > maxn ) {
      maxn = s[j][0] ;
      q = j+1 ;
    }
  cout << q ;
  return 0 ;
}


#include <iostream>
#include<math.h>
using namespace std;

int main()
{  int n,m;
cin>>m>>n;
int arr[m];
int arr1[n][m];
int mx[n];
for(int i=0;i<m;i++)
{
    cin>>arr[i];

}
for(int i=0;i<n;i++)
{
    mx[i]=-1;

}
int j=0;
for(int i=0;i<m;i++)
{ j=0;
 while(arr[i]>0)
 { arr1[i][j]=arr[i]%10;
   mx[j]=max(mx[j],arr1[i][j]);
   arr[i]=arr[i]/10;
     j++;

}}
int c=0;
    for(int i=0;i<m;++i)
    {
        int s=0;
        for(int j=0;j<n;++j)
            if(arr1[i][j]==mx[j])
                s++;
        c+=(s>0);
    }
    cout<<c<<endl;

    return 0;
}


#include <iostream>
#include<math.h>
using namespace std;

int main()
{  int m,n;;
cin>>m>>n;
int arr1[n][m];
int mx[n];
for(int i=0;i<n;i++)
{
    mx[i]=-1;

}
for(int i=0;i<m;i++)
{
    for(int j=0;j<n;j++)
    {
        char c;
        cin>>c;
        arr1[i][j]=c-'0';
        mx[j]=max(mx[j],arr1[i][j]);
    }
}
 int cnt=0;
 for(int i=0;i<m;++i)
    {
        int s=0;
        for(int j=0;j<n;++j)
            if(arr1[i][j]==mx[j])
                {s++;}
                if(s>0)
                    cnt++;
    }
    cout<<cnt;

    return 0;
}


#include <iostream>
#include<math.h>
using namespace std;

int main()
{  int m,n;;
cin>>m>>n;
int arr1[n][m];
int mx[n];
for(int i=0;i<n;i++)
{
    mx[i]=-1;

}
for(int i=0;i<m;i++)
{
    for(int j=0;j<n;j++)
    {
        char c;
        cin>>c;
        arr1[i][j]=c-'0';
        mx[j]=max(mx[j],arr1[i][j]);
    }
}

bool s[n];
for(int i=0;i<n;i++)
    s[i]=0;

    for(int i=0;i<m;++i)
    {

        for(int j=0;j<n;++j)
            if(arr1[i][j]==mx[j])
                {s[j]=1;
                break;}
            }
    int cnt=0;
    for(int i=0;i<n;i++)
           if(s[i])
           cnt++;
    cout<<cnt<<endl;

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    vector<string> v(n);
    vector<int> mx(m);

    for(int i=0;i<m;i++)
    {
        mx[i]=0;
    }
    for(int i=0;i<v.size();i++)
    {
        cin>>v[i];
    }
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {

            if((v[j][i]-'0')> mx[i]){

                mx[i]=(v[j][i]-'0');
                }
        }
    }
    int count=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {

            if((v[i][j]-'0')==mx[j]){count++; break;}
        }
    }
    cout<<count;

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m ;
    cin>>n>>m;
    char c[n][m];
    int arr[n][m];
    for (int i =0  ; i<n ; i++) cin>>c[i] ;
    for (int  i = 0 ; i<n ; i++)
    {
        for (int  j=0 ; j<m; j++)
            arr[i][j] = c[i][j] - '0';
    }
    int mx[m] ;
    for (int j = 0 ; j<m ; j++)
    {
        mx[j]=arr[0][j];
        for (int i= 0 ; i<n ; i++)
            if (mx[j]<arr[i][j]) mx[j]=arr[i][j];

    }
    bool f [n];
    for (int i=0 ; i<n ; i++)
    {
        f[i]=0;
        for (int j=0 ; j<m; j++)
        if (mx[j]==arr[i][j]) {f[i] = true ;break;}
    }
    int cnt=0;
    for (int i = 0 ; i<n ; i++)
    {
        if (f[i]) cnt++;
    }
    cout<<cnt;

    return 0;
}


#include <iostream>
#include<math.h>
using namespace std;

int main()
{  int n,m;
cin>>m>>n;
int arr[m];
int arr1[n][m];
int mx[n];

for(int i=0;i<n;i++)
{
    mx[i]=-1;

}

for(int i=0;i<m;i++)
{
 for(int j=0;j<n;j++)
 {   char c;
     cin>>c;
     arr1[i][j]=c-'0';
   mx[j]=max(mx[j],arr1[i][j]);

}}
int cnt=0;
    for(int i=0;i<m;++i)
    {
        int s=0;
        for(int j=0;j<n;++j)
            if(arr1[i][j]==mx[j])
                s++;
        if(s>0)
        cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int yara[100];
int main()
{
    int n ,m,mx=-1,t=0,Abuamra=0,y=-1;
    cin>>n>>m;
    int a[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
           while(y<n){
                mx=0;
                y++;
        for(int i=0;i<n;i++){

            if(a[i][y]>mx){
                mx=a[i][y];
                t=i;
            }
            if(i==n-1){
                yara[t]++;
                for(int k=0;k<n;k++){
                    if(a[k][y]==mx){
                        yara[k]++;}
                    }
                }
            }}

      for(int i=0;i<n;i++){
        if(yara[i]!=0)
           Abuamra++;
          // cout<<"yara["<<i<<"] = "<<yara[i]<<endl;
      }
      cout<<Abuamra<<endl;
 }


#include<bits/stdc++.h>
using namespace std;
int yara[100];
int main()
{
    int n ,m,mx=-1,Abuamra=0,y=0;
    cin>>n>>m;
    int a[n][m];
    char b[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>b[i][j];
        }
    }
     for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            a[i][j]=b[i-0][j-0];
        }
    }
           while(y<m){
        for(int i=0;i<n;i++){

            if(a[i][y]>mx){
                mx=a[i][y];
            }
            if(i==n-1){
                for(int k=0;k<n;k++){
                    if(a[k][y]==mx){
                        yara[k]++;}
                    }
                      }
                        }
                          y++;
                            mx=-1;

                          }

      for(int i=0;i<n;i++){
        if(yara[i]!=0)
           Abuamra++;
       //  cout<<"yara["<<i<<"] = "<<yara[i]<<endl;
      }
      cout<<Abuamra<<endl;
 }


#include<bits/stdc++.h>
using namespace std;
int yara[100];
int main()
{
    int n ,m,mx=-1,Abuamra=0,y=0;
    cin>>n>>m;
    int a[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
           while(y<m){
        for(int i=0;i<n;i++){

            if(a[i][y]>mx){
                mx=a[i][y];
            }
            if(i==n-1){
                for(int k=0;k<n;k++){
                    if(a[k][y]==mx){
                        yara[k]++;}
                    }
                      }
                        }
                          y++;
                            mx=-1;

                          }

      for(int i=0;i<n;i++){
        if(yara[i]!=0)
           Abuamra++;
       //  cout<<"yara["<<i<<"] = "<<yara[i]<<endl;
      }
      cout<<Abuamra<<endl;
 }


#include<bits/stdc++.h>
using namespace std;
int yara[100];
int main()
{
    int n ,m,mx=-1,t=0,Abuamra=0,y=-1;
    cin>>n>>m;
    int a[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
           while(y<m){
                mx=-1;
                y++;
        for(int i=0;i<n;i++){

            if(a[i][y]>mx){
                mx=a[i][y];
                t=i;
            }
            if(i==n-1){
                yara[t]++;
                for(int k=0;k<n;k++){
                    if(a[k][y]==mx){
                        yara[k]++;}
                    }
                }
            }}

      for(int i=0;i<n;i++){
        if(yara[i]!=0)
           Abuamra++;
     //      cout<<"yara["<<i<<"] = "<<yara[i]<<endl;
      }
      cout<<Abuamra<<endl;
 }


#include<bits/stdc++.h>
using namespace std;
int yara[100];
int main()
{
    int n ,m,mx=-1,Abuamra=0,y=-1;
    cin>>n>>m;
    int a[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
           while(y<m){
        for(int i=0;i<n;i++){

            if(a[i][y]>mx){
                mx=a[i][y];
            }
            if(i==n-1){
                for(int k=0;k<n;k++){
                    if(a[k][y]==mx){
                        yara[k]++;}
                    }
                      }
                        }
                          y++;
                            mx=-1;

                          }

      for(int i=0;i<n;i++){
        if(yara[i]!=0)
           Abuamra++;
       //  cout<<"yara["<<i<<"] = "<<yara[i]<<endl;
      }
      cout<<Abuamra<<endl;
 }


#include<iostream>
using namespace std;
int main(){
    int n,m;
    bool *arr;
    char  **p;
    cin>>n>>m;
    if(n==1)
    cout<<1<<"\n";
    else{
    arr=new bool [n];

    for(int i=0;i<n;i++)
    arr[i]=0;

    p=new char *[n];

    for(int i=0;i<n;i++)
       p[i]=new char[m];

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

    int max,temp;
    for(int i=0;i<m;i++){
           max=0;
           temp=-1;
       for(int k=1;k<n;k++){
               if(p[k][i]>=p[max][i]){
                  if(p[k][i]==p[max][i])
                     temp=k;
                   max=k;
                   }
                   if(temp>0)
                     arr[temp]=1;
               arr[max]=1;

                          }  }
           int ctr=0;
           for(int i=0;i<n;i++)
             if(arr[i])
             ctr++;
             cout<<ctr<<"\n";

  for(int i=0;i<n;i++)
      delete p[i];
      delete []p;
  delete []arr;
}}


#include<iostream>
using namespace std;
int main(){
    int n,m;
    bool *arr;
    char  **p;
    cin>>n>>m;
    arr=new bool [n];

    for(int i=0;i<n;i++)
    arr[i]=0;

    p=new char *[n];

    for(int i=0;i<n;i++)
       p[i]=new char[m];

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

    int max,temp;
    for(int i=0;i<m;i++){
           max=0;
           temp=-1;
       for(int k=1;k<n;k++){
               if(p[k][i]>=p[max][i]){
                  if(p[k][i]==p[max][i])
                     temp=k;
                   max=k;
                   }
                   if(temp>0)
                     arr[temp]=1;
               arr[max]=1;

                          }  }
           int ctr=0;
           for(int i=0;i<n;i++)
             if(arr[i])
             ctr++;
             cout<<ctr<<"\n";

  for(int i=0;i<n;i++)
      delete p[i];
      delete []p;
  delete []arr;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <cstring>

using namespace std;

#define pb push_back
#define len length()
#define clr clear()

#define eps 0.0000001
#define PI  3.14159265359
#define inf 1999888777

int n,m,dp[555],a[333555],b[333555],c[333555];
vector<int> pos[333555];
vector<int>::iterator it;

void upd(int p, int x) {
    for(int i=p; i<=m; i+=i&(-i)) c[i] = max(c[i], x);
}

int findmax(int p) {

    int s = 0;
    for(int i=p; i>0; i-=i&(-i)) s = max(s, c[i]);

    return s;
}

int main() {

    int s,e,i,l,j,t,q,en,os,res,maxj;

    scanf("%d%d%d%d", &n, &m, &s, &e);

    for(i=0; i<n; i++) scanf("%d", &a[i]);
    for(i=0; i<m; i++) {
        scanf("%d", &b[i]);
        pos[b[i]].pb(i+1);
    }

    if (e > s) {
        printf("0\n");
        return 0;
    }

    for(i=0; i<=15500; i++) {
        sort(pos[i].begin(), pos[i].end());
    }

    res = 0;

    maxj = s / e;

    for(i=0; i<=maxj; i++) dp[i] = -1;
    dp[0] = 0;

    for(i=0; i<n; i++) {

        for(j=maxj; j>=1; j--) {

            if (dp[j-1] != -1) {
                it = upper_bound(pos[a[i]].begin(), pos[a[i]].end(), dp[j-1]);
                if (it != pos[a[i]].end()) {
                    t = *it;
                    if (dp[j] == -1 || t < dp[j]) {
                        dp[j] = t;
                        en = j*e + (i+1) + dp[j];
                        if (en <= s) {
                            if (j > res) res = j;
                        }
                    }
                }
            }

        }

    }

    printf("%d\n", res);

    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <cstring>

using namespace std;

#define pb push_back
#define len length()
#define clr clear()

#define eps 0.0000001
#define PI  3.14159265359
#define inf 1999888777

int n,m,a[333555],b[333555],c[333555];
vector<int> pos[333555];

void upd(int p, int x) {
    for(int i=p; i<=m; i+=i&(-i)) c[i] = max(c[i], x);
}

int findmax(int p) {

    int s = 0;
    for(int i=p; i>0; i-=i&(-i)) s = max(s, c[i]);

    return s;
}

int main() {

    int s,e,i,l,j,t,en,res;

    scanf("%d%d%d%d", &n, &m, &s, &e);

    for(i=0; i<n; i++) scanf("%d", &a[i]);
    for(i=0; i<m; i++) {
        scanf("%d", &b[i]);
        pos[b[i]].pb(i+1);
    }

    for(i=0; i<=15500; i++) {
        sort(pos[i].begin(), pos[i].end());
    }

    res = 0;

    for(i=0; i<n; i++) {

        l = pos[ a[i] ].size();
        for(j=l-1; j>=0; j--) {

            t = findmax(pos[ a[i] ][j] - 1) + 1;
            upd(pos[a[i]][j], t);

            en = e*t + (i+1) + (pos[a[i]][j] + 1);

            while(en > s) {
                t--;
                en -= e;
            }

            if (t > res) res = t;
        }
    }

    printf("%d\n", res);

    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <cstring>

using namespace std;

#define pb push_back
#define len length()
#define clr clear()

#define eps 0.0000001
#define PI  3.14159265359
#define inf 1999888777

int n,m,a[333555],b[333555],c[333555];
vector<int> pos[333555];

void upd(int p, int x) {
    for(int i=p; i<=m; i+=i&(-i)) c[i] = max(c[i], x);
}

int findmax(int p) {

    int s = 0;
    for(int i=p; i>0; i-=i&(-i)) s = max(s, c[i]);

    return s;
}

int main() {

    int s,e,i,l,j,t,q,en,os,res;

    scanf("%d%d%d%d", &n, &m, &s, &e);

    for(i=0; i<n; i++) scanf("%d", &a[i]);
    for(i=0; i<m; i++) {
        scanf("%d", &b[i]);
        pos[b[i]].pb(i+1);
    }

    if (e > s) {
        printf("0\n");
        return 0;
    }

    for(i=0; i<=15500; i++) {
        sort(pos[i].begin(), pos[i].end());
    }

    res = 0;

    for(i=0; i<n; i++) {

        l = pos[ a[i] ].size();
        for(j=l-1; j>=0; j--) {

            t = findmax(pos[ a[i] ][j] - 1) + 1;
            upd(pos[a[i]][j], t);

            en = e*t + (i+1) + (pos[a[i]][j] + 1);

            /*while(en > s) {
                t--;
                en -= e;
            }*/
            if (en > s) {
                os = en - s;
                q = os/t + (os%t > 0);
                en -= q*e;
                t -= q;
            }

            if (t > res) res = t;
        }
    }

    printf("%d\n", res);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#define N 200001
#define M 10000001
#define Mod 1000000007
using namespace std;
typedef long long LL;

vector <int> s[N];
struct node{
       int y , next;
}a[N];
int first[N] , b[N] , c[N];
int f[2][305];
int n , m , tot , ss , e;
int ans = 0;

void check(int k,int x){
     ans = max(ans,min(k,(ss-x)/e));
}

void calc(){
     int i , j , x , gun , tt;
     vector<int>::iterator t;
     memset(f,-1,sizeof(f));
     gun = 0; f[0][0] = 0;
     for (i=1;i<=m;++i){
         scanf("%d",&x);
         gun = 1-gun;
         for (j=1;j<=300;++j)
             if (f[1-gun][j-1] != -1){
                               t = lower_bound(s[x].begin(),s[x].end(),f[1-gun][j-1]);
                               if (t != s[x].end())f[gun][j] = *(t);
             }
         for (j=0;j<=300;++j)
             if (f[gun][j] == -1) f[gun][j] = f[1-gun][j]; else
             if (f[1-gun][j] != -1) f[gun][j] = min(f[gun][j],f[1-gun][j]);
         for (j=0;j<=300;++j)
             if (f[gun][j] != -1) check(j,i+f[gun][j]);
     }
}

void add(int x , int y){
     a[tot].y = y; a[tot].next = first[x]; first[x] = tot++;
}

void Solve(){
     int i , x;
     memset(first,-1,sizeof(first));
     cin >> n >> m >> ss >> e;
     tot = 0;
     for (i=1;i<=n;++i){
         scanf("%d",&x);
         s[x].push_back(i);
     }
     ans = 0;
     calc();
     cout << ans << endl;
}

int main(){
    Solve();
    cin >> n;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#define N 400001
#define Mod 1000000007
using namespace std;
typedef long long LL;

struct node{
       int y , next;
}a[N];
int first[N] , b[N] , c[N] , f[N];
int n , m , tot , s , e;
int ans = 0;

void check(int k,int x){
     int p = s - x;
     ans = max(ans,min(k,p/e));
}

int LIS()
{
    int i, k, l, r, mid;
    if (tot == 0) return 0;
    f[1] = b[1], k = 1;
    check(k,n+m-b[1]-c[1]);
    for(i = 2; i <= tot; i++){
        if(f[k] < b[i]){
                f[++k] = b[i];
                check(k,n+m-b[i]-c[i]);
        }
        else {
            l = 1; r = k;
            while(l <= r)
            {
                mid = ( l + r ) / 2;
                if(f[mid] < b[i])
                    l = mid + 1;
                else
                    r = mid - 1;

            }
            f[l] = b[i];
            check(l,n+m-b[i]-c[i]);
        }
    }
    return k;
}

void add(int x , int y){
     a[tot].y = y; a[tot].next = first[x]; first[x] = tot++;
}

void Solve(){
     int i , x;
     memset(first,0,sizeof(first));
     cin >> n >> m >> s >> e;
     tot = 0;
     for (i=1;i<=n;++i){
         scanf("%d",&x);
         add(x,i);
     }
     tot = 0;
     for (i=1;i<=m;++i){
         scanf("%d",&x);
         int j = first[x];
         for (int j=first[x];j;j=a[j].next) b[++tot] = a[j].y , c[tot] = i;
     }
     LIS();
     cout << ans << endl;
}

int main(){
    Solve();
    cin >> n;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#define N 100001
#define Mod 1000000007
using namespace std;
typedef long long LL;
#define N 400005

struct node{
       int y , next;
}a[N];
int first[N] , b[N] , c[N] , f[N];
int n , m , tot , s , e;
LL ans = 0;

int LIS()
{
    int i, k, l, r, mid;
    if (tot == 0) return 0;
    f[1] = b[1], k = 1;
    if (1ll*k*e + n+m-b[1]-c[1] <= s) ans = k;
    for(i = 2; i <= tot; i++){
        if(f[k] < b[i]){
                f[++k] = b[i];
                if (1ll*k*e + n+m-b[i]-c[i] <= s) ans = k;
        }
        else {
            l = 1; r = k;
            while(l <= r)
            {
                mid = ( l + r ) / 2;
                if(f[mid] < b[i])
                    l = mid + 1;
                else
                    r = mid - 1;

            }
            f[l] = b[i];
            if (l == k)
               if (1ll*k*e + n+m-b[i]-c[i] <= s) ans = k;
        }
    }
    return k;
}

void add(int x , int y){
     a[tot].y = y; a[tot].next = first[x]; first[x] = tot++;
}

void Solve(){
     int i , x;
     memset(first,0,sizeof(first));
     cin >> n >> m >> s >> e;
     tot = 0;
     for (i=1;i<=n;++i){
         scanf("%d",&x);
         add(x,i);
     }
     tot = 0;
     for (i=1;i<=m;++i){
         scanf("%d",&x);
         int j = first[x];
         for (int j=first[x];j;j=a[j].next) b[++tot] = a[j].y , c[tot] = i;
     }
     LIS();
     cout << ans << endl;
}

int main(){
    Solve();
    cin >> n;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#define N 400001
#define Mod 1000000007
using namespace std;
typedef long long LL;

struct node{
       int y , next;
}a[N];
int first[N] , b[N] , c[N] , f[N];
int n , m , tot , s , e;
int ans = 0;

void check(int k,int x){
     int p = s - x;
     ans = max(ans,min(k,p/e));
}

int LIS()
{
    int i, k, l, r, mid;
    if (tot == 0) return 0;
    f[1] = b[1], k = 1;
    check(k,n+m-b[1]-c[1]);
    for(i = 2; i <= tot; i++){
        if(f[k] < b[i]){
                f[++k] = b[i];
                check(k,n+m-b[i]-c[i]);
        }
        else {
            l = 1; r = k;
            while(l <= r)
            {
                mid = ( l + r ) / 2;
                if(f[mid] < b[i])
                    l = mid + 1;
                else
                    r = mid - 1;

            }
            f[l] = b[i];
            if (l == k)
               check(k,n+m-b[i]-c[i]);
        }
    }
    return k;
}

void add(int x , int y){
     a[tot].y = y; a[tot].next = first[x]; first[x] = tot++;
}

void Solve(){
     int i , x;
     memset(first,0,sizeof(first));
     cin >> n >> m >> s >> e;
     tot = 0;
     for (i=1;i<=n;++i){
         scanf("%d",&x);
         add(x,i);
     }
     tot = 0;
     for (i=1;i<=m;++i){
         scanf("%d",&x);
         int j = first[x];
         for (int j=first[x];j;j=a[j].next) b[++tot] = a[j].y , c[tot] = i;
     }
     LIS();
     cout << ans << endl;
}

int main(){
    Solve();
    cin >> n;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#define N 400001
#define M 10000001
#define Mod 1000000007
using namespace std;
typedef long long LL;

struct node{
       int y , next;
}a[N];
int first[N] , b[N] , c[N] , f[M];
int n , m , tot , s , e;
int ans = 0;

void check(int k,int x){
     ans = max(ans,min(k,(s+x)/e));
}

int LIS()
{
    int i, k, l, r, mid , x , y;
    f[0] = 0; k = 0;
    for(i = 1; i <= m; i++){
          scanf("%d",&x);
          for (int j=first[x];~j;j=a[j].next){
              y  = a[j].y;
        if(f[k] < y){
                f[++k] = y;
                check(k,n+m-i-y);
        }
        else {
            l = 1; r = k;
            while(l <= r)
            {
                mid = ( l + r ) / 2;
                if(f[mid] < y)
                    l = mid + 1;
                else
                    r = mid - 1;

            }
            f[l] = y;
            check(l,n+m-i-y);
        }
        }
    }
    return k;
}

void add(int x , int y){
     a[tot].y = y; a[tot].next = first[x]; first[x] = tot++;
}

void Solve(){
     int i , x;
     memset(first,-1,sizeof(first));
     cin >> n >> m >> s >> e;
     s -= n+m;
     tot = 0;
     for (i=1;i<=n;++i){
         scanf("%d",&x);
         add(x,i);
     }
     LIS();
     cout << ans << endl;
}

int main(){
    Solve();
    cin >> n;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#define N 200001
#define M 10000001
#define Mod 1000000007
using namespace std;
typedef long long LL;

vector <int> s[N];
struct node{
       int y , next;
}a[N];
int first[N] , b[N] , c[N];
int f[2][305];
int n , m , tot , ss , e;
int ans = 0;

void check(int k,int x){
     ans = max(ans,min(k,(ss-x)/e));
}

void calc(){
     int i , j , x , gun , tt;
     vector<int>::iterator t;
     memset(f,-1,sizeof(f));
     gun = 0; f[0][0] = 0;
     for (i=1;i<=m;++i){
         scanf("%d",&x);
         gun = 1-gun;
         for (j=1;j<=300;++j)
             if (f[1-gun][j-1] != -1){
                               t = lower_bound(s[x].begin(),s[x].end(),f[1-gun][j-1]+1);
                               if (t != s[x].end()) f[gun][j] = *(t);
             }
         for (j=0;j<=300;++j)
             if (f[gun][j] == -1) f[gun][j] = f[1-gun][j]; else
             if (f[1-gun][j] != -1) f[gun][j] = min(f[gun][j],f[1-gun][j]);
         for (j=0;j<=300;++j)
             if (f[gun][j] != -1) check(j,i+f[gun][j]);
     }
}

void add(int x , int y){
     a[tot].y = y; a[tot].next = first[x]; first[x] = tot++;
}

void Solve(){
     int i , x;
     memset(first,-1,sizeof(first));
     cin >> n >> m >> ss >> e;
     tot = 0;
     for (i=1;i<=n;++i){
         scanf("%d",&x);
         s[x].push_back(i);
     }
     ans = 0;
     calc();
     cout << ans << endl;
}

int main(){
    Solve();
    cin >> n;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#define N 400001
#define Mod 1000000007
using namespace std;
typedef long long LL;

struct node{
       int y , next;
}a[N];
int first[N] , b[N] , c[N] , f[N];
int n , m , tot , s , e;
int ans = 0;

void check(int k,int x){
     ans = max(ans,min(k,s/e));
}

int LIS()
{
    int i, k, l, r, mid;
    if (tot == 0) return 0;
    f[1] = b[1], k = 1;
    check(k,n+m-b[1]-c[1]);
    for(i = 2; i <= tot; i++){
        if(f[k] < b[i]){
                f[++k] = b[i];
                check(k,n+m-b[i]-c[i]);
        }
        else {
            l = 1; r = k;
            while(l <= r)
            {
                mid = ( l + r ) / 2;
                if(f[mid] < b[i])
                    l = mid + 1;
                else
                    r = mid - 1;

            }
            f[l] = b[i];
            check(l,n+m-b[i]-c[i]);
        }
    }
    return k;
}

void add(int x , int y){
     a[tot].y = y; a[tot].next = first[x]; first[x] = tot++;
}

void Solve(){
     int i , x;
     memset(first,-1,sizeof(first));
     cin >> n >> m >> s >> e;
     s -= n+m;
     tot = 0;
     for (i=1;i<=n;++i){
         scanf("%d",&x);
         add(x,i);
     }
     tot = 0;
     for (i=1;i<=m;++i){
         scanf("%d",&x);
         for (int j=first[x];~j;j=a[j].next) b[++tot] = a[j].y , c[tot] = i;
     }
     LIS();
     cout << ans << endl;
}

int main(){
    Solve();
    cin >> n;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#define N 400001
#define M 10000001
#define Mod 1000000007
using namespace std;
typedef long long LL;

struct node{
       int y , next;
}a[N];
int first[N] , b[N] , c[N] , f[M];
int n , m , tot , s , e;
int ans = 0;

void check(int k,int x){
     ans = max(ans,min(k,(s+x)/e));
}

int LIS()
{
    int i, k, l, r, mid;
    if (tot == 0) return 0;
    f[1] = b[1], k = 1;
    check(k,n+m-b[1]-c[1]);
    for(i = 2; i <= tot; i++){
        if(f[k] < b[i]){
                f[++k] = b[i];
                check(k,n+m-b[i]-c[i]);
        }
        else {
            l = 1; r = k;
            while(l <= r)
            {
                mid = ( l + r ) / 2;
                if(f[mid] < b[i])
                    l = mid + 1;
                else
                    r = mid - 1;

            }
            f[l] = b[i];
            check(l,n+m-b[i]-c[i]);
        }
    }
    return k;
}

void add(int x , int y){
     a[tot].y = y; a[tot].next = first[x]; first[x] = tot++;
}

void Solve(){
     int i , x;
     memset(first,-1,sizeof(first));
     cin >> n >> m >> s >> e;
     s -= n+m;
     tot = 0;
     for (i=1;i<=n;++i){
         scanf("%d",&x);
         add(x,i);
     }
     tot = 0;
     for (i=1;i<=m;++i){
         scanf("%d",&x);
         for (int j=first[x];~j;j=a[j].next) b[++tot] = a[j].y , c[tot] = i;
     }
     LIS();
     cout << ans << endl;
}

int main(){
    Solve();
    cin >> n;
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <ctime>
#include <cmath>
#include <set>
#include <map>

#define foreach(i,x) for (__typeof (x.begin ()) i = x.begin (); i != x.end (); ++i)

#define all(x) x.begin (), x.end ()
#define vol(x) (int)x.size ()

#define sqr(x) ((x) * (x))
#define abs(x) (((x) > 0) ? (x) : (-(x)))
#define lowbit(x) ((x) & (-(x)))

using namespace std;

typedef long long i64;
typedef unsigned long long u64;
typedef double dbl;

int const N = 100000 + 10;

int n, m, s, e;
int a [N], b [N];
int dp [N][300 + 20];
vector<int> pos [N];

inline void dynamic_programming () {
	int max_times = s / e;

	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= max_times; ++j) {
			dp [i][j] = INT_MAX;
		}
	}

	dp [0][0] = 0;

	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= max_times; ++j) {
			dp [i][j] = dp [i - 1][j];

			if (j >= 1) {
				int limit = dp [i - 1][j - 1];

				vector<int>::iterator it = upper_bound (all (pos [a [i]]), limit);

				if (it != pos [a [i]].end ()) {
					dp [i][j] = min (dp [i][j], *it);
				}
			}
		}
	}
/*
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= max_times; ++j) {
			if (dp [i][j] < INT_MAX) {
				printf ("%d %d %d\n", i, j, dp [i][j]);
			}
		}
	}
*/
}

inline int get () {
	int max_times = s / e;

	int ans = 0;

	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= max_times; ++j) {
			if (dp [i][j] < INT_MAX && (n - i + m - dp [i][j] + j * e) <= s && (i < n || dp [i][j] < m)) {
				ans = max (ans, j);
			}
		}
	}

	return ans;
}

int main () {
	scanf ("%d%d%d%d", &n, &m, &s, &e);

	for (int i = 1; i <= n; ++i) {
		scanf ("%d", a + i);
	}

	for (int i = 1; i <= m; ++i) {
		scanf ("%d", b + i);
	}

	for (int i = 1; i <= m; ++i) {
		pos [b [i]].push_back (i);
	}

	dynamic_programming ();

	printf ("%d\n", get ());

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <ctime>
#include <cmath>
#include <set>
#include <map>

#define foreach(i,x) for (__typeof (x.begin ()) i = x.begin (); i != x.end (); ++i)

#define all(x) x.begin (), x.end ()
#define vol(x) (int)x.size ()

#define sqr(x) ((x) * (x))
#define abs(x) (((x) > 0) ? (x) : (-(x)))
#define lowbit(x) ((x) & (-(x)))

using namespace std;

typedef long long i64;
typedef unsigned long long u64;
typedef double dbl;

int const N = 100000 + 10;

int n, m, s, e;
int a [N], b [N];
int dp [N][300 + 20];
vector<int> pos [N];

inline void dynamic_programming () {
	int max_times = s / e;

	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= max_times; ++j) {
			dp [i][j] = INT_MAX;
		}
	}

	dp [0][0] = 0;

	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= max_times; ++j) {
			dp [i][j] = dp [i - 1][j];

			if (j >= 1) {
				int limit = dp [i - 1][j - 1];

				vector<int>::iterator it = upper_bound (all (pos [a [i]]), limit);

				if (it != pos [a [i]].end ()) {
					dp [i][j] = min (dp [i][j], *it);
				}
			}
		}
	}
/*
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= max_times; ++j) {
			if (dp [i][j] < INT_MAX) {
				printf ("%d %d %d\n", i, j, dp [i][j]);
			}
		}
	}
*/
}

inline int get () {
	int max_times = s / e;

	int ans = 0;

	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= max_times; ++j) {
			if (dp [i][j] < INT_MAX && (n - i + m - dp [i][j] + j * e) <= s) {
				ans = max (ans, j);
			}
		}
	}

	return ans;
}

int main () {
	scanf ("%d%d%d%d", &n, &m, &s, &e);

	for (int i = 1; i <= n; ++i) {
		scanf ("%d", a + i);
	}

	for (int i = 1; i <= m; ++i) {
		scanf ("%d", b + i);
	}

	for (int i = 1; i <= m; ++i) {
		pos [b [i]].push_back (i);
	}

	dynamic_programming ();

	printf ("%d\n", get ());

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <ctime>
#include <cmath>
#include <set>
#include <map>

#define foreach(i,x) for (__typeof (x.begin ()) i = x.begin (); i != x.end (); ++i)

#define all(x) x.begin (), x.end ()
#define vol(x) (int)x.size ()

#define sqr(x) ((x) * (x))
#define abs(x) (((x) > 0) ? (x) : (-(x)))
#define lowbit(x) ((x) & (-(x)))

using namespace std;

typedef long long i64;
typedef unsigned long long u64;
typedef double dbl;

int const N = 100000 + 10;

int n, m, s, e;
int a [N], b [N];
int dp [N][300 + 20];
vector<int> pos [N];

inline void dynamic_programming () {
	int max_times = s / e;

	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= max_times; ++j) {
			dp [i][j] = INT_MAX;
		}
	}

	dp [0][0] = 0;

	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= max_times; ++j) {
			dp [i][j] = dp [i - 1][j];

			if (j >= 1) {
				int limit = dp [i - 1][j - 1];

				vector<int>::iterator it = upper_bound (all (pos [a [i]]), limit);

				if (it != pos [a [i]].end ()) {
					dp [i][j] = min (dp [i][j], *it);
				}
			}
		}
	}
/*
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= max_times; ++j) {
			if (dp [i][j] < INT_MAX) {
				printf ("%d %d %d\n", i, j, dp [i][j]);
			}
		}
	}
*/
}

inline int get () {
	int max_times = s / e;

	int ans = 0;

	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= max_times; ++j) {
			if (dp [i][j] < INT_MAX && (i + dp [i][j] + j * e) <= s) {
				ans = max (ans, j);
			}
		}
	}

	return ans;
}

int main () {
	scanf ("%d%d%d%d", &n, &m, &s, &e);

	for (int i = 1; i <= n; ++i) {
		scanf ("%d", a + i);
	}

	for (int i = 1; i <= m; ++i) {
		scanf ("%d", b + i);
	}

	for (int i = 1; i <= m; ++i) {
		pos [b [i]].push_back (i);
	}

	dynamic_programming ();

	printf ("%d\n", get ());

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <ctime>
#include <cmath>
#include <set>
#include <map>

#define foreach(i,x) for (__typeof (x.begin ()) i = x.begin (); i != x.end (); ++i)

#define all(x) x.begin (), x.end ()
#define vol(x) (int)x.size ()

#define sqr(x) ((x) * (x))
#define abs(x) (((x) > 0) ? (x) : (-(x)))
#define lowbit(x) ((x) & (-(x)))

using namespace std;

typedef long long i64;
typedef unsigned long long u64;
typedef double dbl;

int const N = 200;

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

inline int bit_get () {
	static int x [N];
	int ans = k + 1;

	for (int mask = 0; mask < (1 << n); ++mask) {
		for (int i = 1; i <= n; ++i) {
			x [i] = (mask >> i - 1) & 1;
		}

		int sum = 0;

		for (int j = 1; j <= m; ++j) {
			int num = 0;
			for (int i = 1; i <= n; ++i) {
				if (a [i][j] == x [i]) {
					num++;
				}
			}
			sum += min (num, n - num);
		}

		ans = min (ans, sum);
	}

	return ans;
}

inline int brute_force_get () {
	static int y [N];

	int ans = k + 1;

	for (int idx = 1; idx <= n; ++idx) {
		for (int j = 1; j <= m; ++j) {
			y [j] = a [idx][j];
		}

		int sum = 0;

		for (int i = 1; i <= n; ++i) {
			int num = 0;

			for (int j = 1; j <= m; ++j) {
				if (a [i][j] == y [j]) {
					num++;
				}
			}

			sum += min (num, m - num);
		}

		ans = min (ans, sum);
	}

	return ans;
}

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);
		}
	}

	int ans = (n <= k) ? bit_get () : brute_force_get ();

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

	return 0;
}


#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int MX = 100010;
int n, m, s, e;
int a[MX], b[MX];
int right_a[MX], right_b[MX];
int dp[MX]; //dp[�ő��]: �ŏ��ʒu

int main(){
	cin >> n >> m >> s >> e;
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];

	set<pi> bs;
	map<int, int> pos;
	rep(i, m){
		pos[b[i]] = i;
		bs.insert(mp(b[i], i));
	}
	rep(i, m) right_b[i] = pos[b[i]];
	pos.clear();
	rep(i, n) pos[a[i]] = i;
	rep(i, n) right_a[i] = pos[a[i]];

	int ans = 0;
	int lim = s / e;
	rep(i, lim + 1) dp[i] = inf;
	dp[0] = 0;

	rep(i, n) for(int j = lim; j >= 0; j--) if(dp[j] < inf){

		set<pi>::iterator it = bs.lower_bound(mp(a[i], dp[j] + 1));
		if(it != bs.end() && it->first == a[i]){
			dp[j + 1] = min(dp[j + 1], it->second);

			int cost = n - m - right_a[a[i]] - right_b[b[it->second]];
			if(cost + (j + 1) * e <= s) ans = max(ans, j + 1);
		}
	}
	cout << ans << endl;

	return 0;
}


#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int MX = 100010;
int n, m, s, e;
int a[MX], b[MX];
int right_a[MX], right_b[MX];
int dp[MX]; //dp[�ő��]: �ŏ��ʒu

int main(){
	cin >> n >> m >> s >> e;
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];

	set<pi> bs;
	map<int, int> pos;
	rep(i, m){
		pos[b[i]] = i;
		bs.insert(mp(b[i], i));
	}
	rep(i, m) right_b[i] = pos[b[i]];
	pos.clear();
	rep(i, n) pos[a[i]] = i;
	rep(i, n) right_a[i] = pos[a[i]];

	int ans = 0;
	int lim = s / e;
	rep(i, lim + 1) dp[i] = inf;
	dp[0] = -1;

	rep(i, n) for(int j = lim; j >= 0; j--) if(dp[j] < inf){

		set<pi>::iterator it = bs.lower_bound(mp(a[i], dp[j] + 1));
		if(it != bs.end() && it->first == a[i]){
			dp[j + 1] = min(dp[j + 1], it->second);

			int cost = i + it->second + 2;
			if(cost + (j + 1) * e <= s) ans = max(ans, j + 1);
		}
	}
	cout << ans << endl;

	return 0;
}


#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int MX = 131072;
int bit[MX];
void add(int i, int x){
	for(i++; i < MX; i += i & -i) bit[i] += x;
}
int sum(int i){
	int res = 0;
	for(i++; i; i -= i & -i) res += bit[i];
	return res;
}
inline int find(int k){
	int lo = 0, hi = MX, mid;
	while(lo + 1 < hi){
		mid = (lo + hi) / 2;
		if(bit[mid] >= k) hi = mid;
		else lo = mid, k -= bit[mid];
	}
	return lo;
}

struct RMQ{
	int *dat;
	int sz;
	RMQ(int n){
		for(sz = 1; sz < n; sz *= 2);
		dat = new int[2 * sz];
		rep(i, 2 * sz) dat[i] = -1;
	}
	int query(int a, int b){ return query(a, b, 0, 0, sz);}
	int query(int a, int b, int k, int l, int r){
		if(b <= l || a >= r) return -inf;
		if(a <= l && r <= b) return dat[k];
		return max(
			query(a, b, k * 2 + 1, l, (l + r) / 2),
			query(a, b, k * 2 + 2, (l + r) / 2, r));
	}
	void fix(int k, int x){
		k += sz - 1;
		dat[k] = x;
		while(k){
			k = (k - 1) / 2;
			dat[k] = max(dat[k], x);
		}
	}
};

int n, m, s, e;
int a[MX], b[MX], la[MX], lb[MX];

void in(int n, int *a, int *la){
	memset(bit, 0, sizeof(bit));
	vector<pi> v;

	rep(i, n){
		scanf("%d", a + i + 1);
		v.pb(mp(-a[i + 1], i + 1));
	}
	sort(all(v));

	rep(i, n){
		int s = sum(v[i].second);
		/*
		cerr<<-v[i].first<<" "<<v[i].second<<endl;
		dbg(s); dbg(find(s));
		*/
		if(s) la[-v[i].first] = find(s);
		add(v[i].second, 1);
	}
}

int main(){
	scanf("%d%d%d%d", &n, &m, &s, &e);
	in(n, a, la);
	in(m, b, lb);

	#if 0
	rep(i, n) dbg(a[i + 1]); rep(i, m) dbg(b[i + 1]);
	rep(i, n) dbg(lb[i + 1]);
	#endif

	int ans = 0;
	static int posa[MX];
	memset(posa, -1, sizeof(posa));
	rep(i, n + 1) posa[a[i]] = i;

	RMQ *rmq[310];
	rep(i, 310) rmq[i] = new RMQ(n + 1);

	s /= e;

	rep(i, m){
		int X = posa[b[i + 1]];
		if(X < 0) continue;

		int x = la[b[i + 1]];
		int Y = i + 1, y = lb[b[i + 1]];
		int mx = 0;
		/*
		dbg(b[i + 1]);
		cerr<<"x: "<<x<<" X: "<<X<<" y: "<<y<<" Y: "<<Y<<endl;
		*/
		for(int j = s; j > 0; j--){
			if(rmq[j]->query(x, X) >= y){
				mx = j;
				break;
			}
		}
		mx = min(mx + 1, s);
		ans = max(ans, mx);
		rmq[mx]->fix(X, Y);
	}
	cout << ans << endl;

	return 0;
}