wrong answer always to offside(spoj)
I have written a code 
its an easy code but when i try to post it in spoj it gives me wrong answer can anyone tell me whats wrong in my code , may be i am missing something ,problem statement is here[  offside][1] . it is about the offside situation in SOCCER

    #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<cstdio>
    #include<stdlib.h>
    
    using namespace std;
    
    #define MAX 10000;
    
    int main()
    {
    	vector<long long int> v1,v2;
    	long long int a,b,c,d,i,z=MAX;
    	scanf("%lld %lld",&a,&b);
    	while (a!=0 && b!=0)
    	{
    		for(i=0;i<a;i++)
    		{
    			scanf("%lld",&c);
    			if(z>c)
    			{
    				z=c;
    			}
    		}
    		for(i=0;i<b;i++)
    		{
    			scanf("%lld",&d);
    			v2.push_back(d);
    		}
    		sort(v2.begin(),v2.end());
    	
    		if (z < v2[1])
    		printf("Y\n");
    		else
    		printf("N\n");
    		scanf("%lld %lld",&a,&b);
    	}		
    	return 0;
    }


  [1]: http://www.spoj.pl/problems/OFFSIDE/
wrong answer always to offside(spoj)
===

I have written a code 
its an easy code but when i try to post it in spoj it gives me wrong answer can anyone tell me whats wrong in my code , may be i am missing something ,problem statement is here[  offside][1] . it is about the offside situation in SOCCER

    #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<cstdio>
    #include<stdlib.h>
    
    using namespace std;
    
    #define MAX 10000;
    
    int main()
    {
    	vector<long long int> v1,v2;
    	long long int a,b,c,d,i,z=MAX;
    	scanf("%lld %lld",&a,&b);
    	while (a!=0 && b!=0)
    	{
    		for(i=0;i<a;i++)
    		{
    			scanf("%lld",&c);
    			if(z>c)
    			{
    				z=c;
    			}
    		}
    		for(i=0;i<b;i++)
    		{
    			scanf("%lld",&d);
    			v2.push_back(d);
    		}
    		sort(v2.begin(),v2.end());
    	
    		if (z < v2[1])
    		printf("Y\n");
    		else
    		printf("N\n");
    		scanf("%lld %lld",&a,&b);
    	}		
    	return 0;
    }


  [1]: http://www.spoj.pl/problems/OFFSIDE/