#include <bits/stdc++.h>
#define ll long long
#define uint unsigned int
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pp pair<int,int>
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
#define per(ii,a,b) for(int ii=a;ii>=b;ii--)
#define show(x) cout<<#x<<"="<<x<<endl
#define show2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define show3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define showa(b,a) cout<<#a<<"["<<b<<"]="<<a[b]<<endl;
using namespace std;
const int maxn=1e5+10;
const int maxm=2e7+10;
const ll INF=(1<<30);
int casn,n,m,k;
ll sum[maxn];
ll num[maxn];
int main(){
//#define test
#ifdef test
    freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
	IO;
	ll a,b,c,d;
	cin>>n>>a>>b>>d;
	n--;
	rep(i,1,n) cin>>num[i];
	c=d*a;
	sort(num+1,num+n+1);
	rep(i,1,n) sum[i]=sum[i-1]+num[i];
	if((d+sum[n])*b<=c){
		cout<<0<<endl;
		return 0;
	}
	if(a==b){
		int ans=0;
		cout<<n<<endl;
		return 0;
	}
	int l=1,r=n;
	int ans=INF;
	while(l<=r){
		int mid=(l+r)>>1;
		if((d+sum[mid])*b<=c){
			ans=min(ans,mid);
			r=mid-1;
		}else l=mid+1;
	}
	cout<<ans<<endl;
#ifdef test
    fclose(stdin);fclose(stdout);system("out.txt");
#endif
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define uint unsigned int
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pp pair<int,int>
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
#define per(ii,a,b) for(int ii=a;ii>=b;ii--)
#define show(x) cout<<#x<<"="<<x<<endl
#define show2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define show3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define showa(b,a) cout<<#a<<"["<<b<<"]="<<a[b]<<endl;
using namespace std;
const int maxn=1e5+10;
const int maxm=2e7+10;
const ll INF=(1<<30);
int casn,n,m,k;
ll sum[maxn];
ll num[maxn];
int cmp(ll a,ll b){
	return a>b;
}
int main(){
//#define test
#ifdef test
    freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
	IO;
	ll a,b,c,d;
	cin>>n>>a>>b;
	rep(i,1,n) cin>>num[i];
	sort(num+2,num+1+n);
	ll sum=0;
	int ans=INF;
	rep(i,1,n){
		if((num[1]+sum)*b<=num[1]*a){
			ans=min(ans,n-i);
		}
		sum+=num[i];
	}
	cout<<ans<<endl;
#ifdef test
    fclose(stdin);fclose(stdout);system("out.txt");
#endif
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define uint unsigned int
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pp pair<int,int>
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
#define per(ii,a,b) for(int ii=a;ii>=b;ii--)
#define show(x) cout<<#x<<"="<<x<<endl
#define show2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define show3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define showa(b,a) cout<<#a<<"["<<b<<"]="<<a[b]<<endl;
using namespace std;
const int maxn=1e5+10;
const int maxm=2e7+10;
const ll INF=(1<<30);
int casn,n,m,k;
ll sum[maxn];
ll num[maxn];
int cmp(ll a,ll b){
	return a>b;
}
int main(){
//#define test
#ifdef test
    freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
	IO;
	ll a,b,c,d;
	cin>>n>>a>>b;
	rep(i,1,n) cin>>num[i];
	d=num[1];
	sort(num+2,num+1+n,cmp);
	rep(i,2,n){
		sum[i]=sum[i-1]+num[i];
	}
	int ans=INF;
	rep(i,1,n){
		if((sum[i]+d)*b<=a*d){
			ans=min(ans,n-i);
		}
	}
	cout<<ans<<endl;
#ifdef test
    fclose(stdin);fclose(stdout);system("out.txt");
#endif
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define uint unsigned int
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pp pair<int,int>
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
#define per(ii,a,b) for(int ii=a;ii>=b;ii--)
#define show(x) cout<<#x<<"="<<x<<endl
#define show2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define show3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define showa(b,a) cout<<#a<<"["<<b<<"]="<<a[b]<<endl;
using namespace std;
const int maxn=2e6+10;
const int maxm=2e7+10;
const int INF=0x3f3f3f3f;
int casn,n,m,k;
ll sum[maxn];
ll num[maxn];
int main(){
//#define test
#ifdef test
    freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
	IO;
	ll a,b,c,d;
	cin>>n>>a>>b;
	rep(i,1,n) cin>>num[i];
	sort(num+2,num+1+n);
	ll sum=0;
	int ans=n-1;
	rep(i,2,n){
		if((num[1]+sum)*b<=num[1]*a){
			ans=n-i+1;
		}
		sum+=num[i];
	}
	if((num[1]+sum)*b<=num[1]*a) ans=0;
	cout<<ans<<endl;
#ifdef test
    fclose(stdin);fclose(stdout);system("out.txt");
#endif
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define uint unsigned int
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pp pair<int,int>
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
#define per(ii,a,b) for(int ii=a;ii>=b;ii--)
#define show(x) cout<<#x<<"="<<x<<endl
#define show2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define show3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define showa(b,a) cout<<#a<<"["<<b<<"]="<<a[b]<<endl;
using namespace std;
const int maxn=1e5+10;
const int maxm=2e7+10;
const ll INF=(1<<30);
int casn,n,m,k;
ll sum[maxn];
ll num[maxn];
int cmp(ll a,ll b){
	return a>b;
}
int main(){
//#define test
#ifdef test
    freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
	IO;
	ll a,b,c,d;
	cin>>n>>a>>b;
	rep(i,1,n) cin>>num[i];
	if(a==b){
		cout<<n-1<<endl;
		return 0;
	}
	d=num[1];
	sort(num+2,num+1+n,cmp);
	rep(i,2,n){
		sum[i]=sum[i-1]+num[i];
	}
	if((sum[n]+d)*b<=a*d){
		cout<<0<<endl;
		return 0;
	}
	int ans=INF;
	rep(i,1,n){
		if((sum[i]+d)*b<=a*d){
			ans=min(ans,n-i);
		}
	}
	cout<<ans<<endl;
#ifdef test
    fclose(stdin);fclose(stdout);system("out.txt");
#endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n, A, B; cin >> n >> A >> B;
  long long sum = 0;
  int x, s[101010]; cin >> x; sum = x;
  for (int i = 0; i < n-1; i++) cin >> s[i], sum += s[i];
  sort(s, s+n-1, greater<int>());
  int ret = 0;
  for (int i = 0; i < n-1; i++) {
    if (x*A >= (long long)sum*B) break;
    sum -= s[i]; ret++;
  }
  cout << ret;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, A, B; cin >> n >> A >> B;
  int x, s[10100]; cin >> x;
  for (int i = 0; i < n-1; i++) cin >> s[i];
  sort(s, s+n-1, greater<int>());
  int sum = accumulate(s, s+n-1, 0) + x;
  int ret = 0;
  for (int i = 0; i < n-1; i++) {
    if (x*A >= (long long)sum*B) break;
    sum -= s[i]; ret++;
  }
  cout << ret;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n, A, B; cin >> n >> A >> B;
  long long sum = 0;
  int x, s[10100]; cin >> x; sum = x;
  for (int i = 0; i < n-1; i++) cin >> s[i], sum += s[i];
  sort(s, s+n-1, greater<int>());
  int ret = 0;
  for (int i = 0; i < n-1; i++) {
    if (x*A >= (long long)sum*B) break;
    sum -= s[i]; ret++;
  }
  cout << ret;
}


#include <bits/stdc++.h>
using namespace std;
const double EPS = 1E-9;
int cmp(double a, double b, double tol = EPS) {
  return (a <= b + tol) ? (a + tol < b) ? -1 : 0 : 1;
}
int main() {
  int n, A, B; cin >> n >> A >> B;
  int x, s[10100]; cin >> x;
  for (int i = 0; i < n-1; i++) cin >> s[i];
  sort(s, s+n-1, greater<int>());
  int sum = accumulate(s, s+n-1, 0) + x;
  int ret = 0;
  for (int i = 0; i < n-1; i++) {
    if (cmp(x*A/(double)sum, B) >= 0) break;
    sum -= s[i]; ret++;
  }
  cout << ret;
}


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

long long n,A,B,sum=0,a[100005];

int main()
{
	ios_base::sync_with_stdio(false);
	//freopen("967B.INP","r",stdin);
	//freopen("967B.OUT","w",stdout);
	cin>>n>>A>>B;
	for(long long i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	sort(a+2,a+n+1);
	for(long long i=n;i>=1;i--)
	{
		if(a[1]*A>=sum*B)
		{
			cout<<n-i;
			return 0;
		}
		sum-=a[i];
	}
}


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

long long n,A,B,sum=0,a[10005];

int main()
{
	ios_base::sync_with_stdio(false);
	//freopen(".INP","r",stdin);
	//freopen(".OUT","w",stdout);
	cin>>n>>A>>B;
	for(long long i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	sort(a+2,a+n+1,greater<long long>());
	if(a[1]*A/sum>=B)
		cout<<0;
	else
	for(long long i=2;i<=n;i++)
	{
		sum-=a[i];
		if(a[1]*A/sum>=B)
		{
			cout<<i-1;
			return 0;
		}
	}
}


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

long long n,A,B,sum=0,a[10005];

int main()
{
	ios_base::sync_with_stdio(false);
	//freopen("967B.INP","r",stdin);
	//freopen("967B.OUT","w",stdout);
	cin>>n>>A>>B;
	for(long long i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	sort(a+2,a+n+1,greater<long long>());
	if(a[1]*A>=sum*B)
		cout<<0;
	else
	for(long long i=2;i<=n;i++)
	{
		sum-=a[i];
		if(a[1]*A>=sum*B)
		{
			cout<<i-1;
			return 0;
		}
	}
}


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

long long n,A,B,sum=0,a[10005];

int main()
{
	ios_base::sync_with_stdio(false);
	//freopen("967B.INP","r",stdin);
	//freopen("967B.OUT","w",stdout);
	cin>>n>>A>>B;
	for(long long i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	sort(a+2,a+n+1);
	for(long long i=n;i>=1;i--)
	{
		if(a[1]*A>=sum*B)
		{
			cout<<n-i;
			return 0;
		}
		sum-=a[i];
	}
}


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

int n,A,B,sum=0,a[10005];

int main()
{
	ios_base::sync_with_stdio(false);
	//freopen(".INP","r",stdin);
	//freopen(".OUT","w",stdout);
	cin>>n>>A>>B;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	sort(a+2,a+n+1,greater<int>());
	if(a[1]*A/sum>=B)
		cout<<0;
	else
	for(int i=2;i<=n;i++)
	{
		sum-=a[i];
		if(a[1]*A/sum>=B)
		{
			cout<<i-1;
			return 0;
		}
	}
}


using namespace std;
bool debug = false;

//<editor-fold desc="GUAXINIM TEMPLATE">
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define all(container) container.begin(), container.end()
#define mp(i,j) make_pair(i,j)
#define space " "

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vii;

/// Debug Start
template<class T1> void deb(T1 e1)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << endl;
    }
}
template<class T1,class T2> void deb(T1 e1, T2 e2)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << endl;
    }
}
template<class T1,class T2,class T3> void deb(T1 e1, T2 e2, T3 e3)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << endl;
    }
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1, T2 e2, T3 e3, T4 e4)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << endl;
    }
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << space << e5 << endl;
    }
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1, T2 e2, T3 e3, T4 e4 ,T5 e5, T6 e6)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << space << e5 << space << e6 << endl;
    }
}

template<typename T>
void print_vector_debug(const T& t) {

    if(debug) {
        cout << "[DEBUG] VECTOR:";
        for (auto i = t.cbegin(); i != t.cend(); ++i) {
            if ((i + 1) != t.cend()) {
                cout << *i << " ";
            } else {
                cout << *i << endl;
            }
        }
    }
}

template<typename T>
void print_array_debug(const T arr, int size){

    if(debug) {
        cout << "[DEBUG] VECTOR:";
        for (int i = 0; i < size; ++i) {
            cout << arr[i] << space;
        }
        cout << endl;
    }
}

template<typename T>
void print_2Darray_debug(const T arr, int rows, int cols){

    if(debug) {
        cout << "[DEBUG] Matrix:" << endl;
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                cout << arr[i][j] << space;
            }
            cout << endl;
        }
        cout << endl;
    }
}

template<typename T>
void print_matrix_debug(const T& t) {
    if(debug) {
        cout << "[DEBUG] MATRIX:" << endl;
        for (auto i = t.cbegin(); i != t.cend(); ++i) {
            for(auto j = i->cbegin(); j != i->cend(); ++j){
                cout << *j << " ";
            }
            cout << endl;
        }
    }
}
//</editor-fold>

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n_holes, A, B;
    cin >> n_holes >> A >> B;

    int first_hole_sz;
    cin >> first_hole_sz;

    vi holes_sz(n_holes - 1);
    double total_sum_hole = first_hole_sz;

    for (size_t i = 0; i < n_holes; i++) {
        cin >> holes_sz[i];
        total_sum_hole += holes_sz[i];
    }

    sort(all(holes_sz));
    reverse(all(holes_sz));

    double dividendo = A * first_hole_sz;
    int blocked = 0;

    for (auto &hole : holes_sz) {
        if (dividendo / total_sum_hole >= B) {
            break;
        }

        total_sum_hole -= hole;
        ++blocked;
    }

    cout << blocked << endl;

    return 0;
}


using namespace std;
bool debug = false;

//<editor-fold desc="GUAXINIM TEMPLATE">
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define all(container) container.begin(), container.end()
#define mp(i,j) make_pair(i,j)
#define space " "

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vii;

/// Debug Start
template<class T1> void deb(T1 e1)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << endl;
    }
}
template<class T1,class T2> void deb(T1 e1, T2 e2)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << endl;
    }
}
template<class T1,class T2,class T3> void deb(T1 e1, T2 e2, T3 e3)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << endl;
    }
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1, T2 e2, T3 e3, T4 e4)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << endl;
    }
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << space << e5 << endl;
    }
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1, T2 e2, T3 e3, T4 e4 ,T5 e5, T6 e6)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << space << e5 << space << e6 << endl;
    }
}

template<typename T>
void print_vector_debug(const T& t) {

    if(debug) {
        cout << "[DEBUG] VECTOR:";
        for (auto i = t.cbegin(); i != t.cend(); ++i) {
            if ((i + 1) != t.cend()) {
                cout << *i << " ";
            } else {
                cout << *i << endl;
            }
        }
    }
}

template<typename T>
void print_array_debug(const T arr, int size){

    if(debug) {
        cout << "[DEBUG] VECTOR:";
        for (int i = 0; i < size; ++i) {
            cout << arr[i] << space;
        }
        cout << endl;
    }
}

template<typename T>
void print_2Darray_debug(const T arr, int rows, int cols){

    if(debug) {
        cout << "[DEBUG] Matrix:" << endl;
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                cout << arr[i][j] << space;
            }
            cout << endl;
        }
        cout << endl;
    }
}

template<typename T>
void print_matrix_debug(const T& t) {
    if(debug) {
        cout << "[DEBUG] MATRIX:" << endl;
        for (auto i = t.cbegin(); i != t.cend(); ++i) {
            for(auto j = i->cbegin(); j != i->cend(); ++j){
                cout << *j << " ";
            }
            cout << endl;
        }
    }
}
//</editor-fold>

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n_holes, A, B;
    cin >> n_holes >> A >> B;

    int first_hole_sz;
    cin >> first_hole_sz;

    if (n_holes == 1) {
        cout << 0 << endl;
        return 0;
    }

    vi holes_sz(n_holes - 1);
    double total_sum_hole = first_hole_sz;

    for (size_t i = 0; i < n_holes; i++) {
        cin >> holes_sz[i];
        total_sum_hole += holes_sz[i];
    }

    sort(all(holes_sz));
    reverse(all(holes_sz));

    double dividendo = A * first_hole_sz;
    int blocked = 0;

    for (auto &hole : holes_sz) {
        if (dividendo / total_sum_hole >= B) {
            break;
        }

        total_sum_hole -= hole;
        ++blocked;
    }

    cout << blocked << endl;

    return 0;
}


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

#define db(x) cerr << #x << " == " << x << endl
#define all(container) container.begin(), container.end()
#define mp(i,j) make_pair(i,j)
#define pb push_back

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vii;

template<typename T>
void print_vector_debug(const T& t) {
	cout << "[DEBUG] VECTOR:";
	for (auto i = t.cbegin(); i != t.cend(); ++i) {
		if ((i + 1) != t.cend()) {
			cout << *i << " ";
		} else {
			cout << *i << endl;
		}
	}
}

int main()
{

	int N, A, B;

	scanf("%d%d%d", &N, &A, &B);

	multiset<ll, greater<ll>> holes;

	ll first_hole;
	ll S = 0;

	scanf("%lld", &first_hole);

	S += first_hole;

	ll v;
	for (int i = 1; i < N; i++)
	{
		scanf("%lld", &v);
		S += v;
		holes.insert(v);
	}

	int ans = 0;
	for (ll i : holes)
	{
		if (first_hole*A/S >= B)
		{
			break;
		}

		S -= i;
		ans++;
	}

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

	return 0;
}


using namespace std;
bool debug = false;

//<editor-fold desc="GUAXINIM TEMPLATE">
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define all(container) container.begin(), container.end()
#define mp(i,j) make_pair(i,j)
#define space " "

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vii;

/// Debug Start
template<class T1> void deb(T1 e1)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << endl;
    }
}
template<class T1,class T2> void deb(T1 e1, T2 e2)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << endl;
    }
}
template<class T1,class T2,class T3> void deb(T1 e1, T2 e2, T3 e3)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << endl;
    }
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1, T2 e2, T3 e3, T4 e4)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << endl;
    }
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << space << e5 << endl;
    }
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1, T2 e2, T3 e3, T4 e4 ,T5 e5, T6 e6)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << space << e5 << space << e6 << endl;
    }
}

template<typename T>
void print_vector_debug(const T& t) {

    if(debug) {
        cout << "[DEBUG] VECTOR:";
        for (auto i = t.cbegin(); i != t.cend(); ++i) {
            if ((i + 1) != t.cend()) {
                cout << *i << " ";
            } else {
                cout << *i << endl;
            }
        }
    }
}

template<typename T>
void print_array_debug(const T arr, int size){

    if(debug) {
        cout << "[DEBUG] VECTOR:";
        for (int i = 0; i < size; ++i) {
            cout << arr[i] << space;
        }
        cout << endl;
    }
}

template<typename T>
void print_2Darray_debug(const T arr, int rows, int cols){

    if(debug) {
        cout << "[DEBUG] Matrix:" << endl;
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                cout << arr[i][j] << space;
            }
            cout << endl;
        }
        cout << endl;
    }
}

template<typename T>
void print_matrix_debug(const T& t) {
    if(debug) {
        cout << "[DEBUG] MATRIX:" << endl;
        for (auto i = t.cbegin(); i != t.cend(); ++i) {
            for(auto j = i->cbegin(); j != i->cend(); ++j){
                cout << *j << " ";
            }
            cout << endl;
        }
    }
}
//</editor-fold>

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n_holes, A, B;
    cin >> n_holes >> A >> B;

    int first_hole_sz;
    cin >> first_hole_sz;

    if (n_holes == 1) {
        cout << 0 << endl;
        return 0;
    }

    vi holes_sz(n_holes - 1);
    double total_sum_hole = first_hole_sz;

    for (size_t i = 0; i < n_holes - 1; i++) {
        cin >> holes_sz[i];
        total_sum_hole += holes_sz[i];
    }

    sort(all(holes_sz));
    reverse(all(holes_sz));

    double dividendo = A * first_hole_sz;
    int blocked = 0;

    for (auto &hole : holes_sz) {
        if (dividendo / total_sum_hole >= B) {
            break;
        }

        total_sum_hole -= hole;
        ++blocked;
    }

    cout << blocked << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,a,b,k=0;
    scanf("%d%d%d",&n,&a,&b);
    int s[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&s[i]);
        k=k+s[i];
    }
    i=n-1;
    sort(s+1,s+n);
    while(i>0&b>1.0*a*s[0]/k)
      k=k-s[i--];
    printf("%d",(n-1)-i);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,a,b,k=0;
    scanf("%d%d%d",&n,&a,&b);
    int s[10001];
    for(i=0;i<n;i++)
    {
        scanf("%d",&s[i]);
        k=k+s[i];
    }
    i=n-1;
    sort(s+1,s+n);
    while(i>0&b>1.0*a*s[0]/k)
      k=k-s[i--];
    printf("%d",(n-1)-i);
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n,a,b,total=0;
cin>>n>>a>>b;
ll arr[n];
for(ll i=0;i<n;i++)
{
cin>>arr[i];
total+=arr[i];
}
sort(arr+1,arr+n);
reverse(arr+1,arr+n);

float w=(arr[0]*a)/total;
ll i=n-1,count=0;
while(w<b)
{
	total=total-arr[i];
	count++;
	w=(arr[0]*a)/total;
}
cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	vector<int>v(n);
	int s[n] = {0};
	int t_s = 0;
	for(int i=0;i<n;i++)
	cin>>v[i];
	sort(v.begin()+1,v.end());
	s[0]=v[0];
	t_s = v[0];
	for(int i=1;i<n;i++){
	s[i]= s[i-1]+v[i];
	t_s = t_s + v[i];
}
   for(int i=n-1;i>=0;i--)
   {
   	if((a*v[0])/s[i]>=b){
   	cout<<n-i-1;
    break;
   }
}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n,a,b,total=0;
cin>>n>>a>>b;
ll arr[n];
for(ll i=0;i<n;i++)
{
cin>>arr[i];
total+=arr[i];
}
sort(arr+1,arr+n);
//reverse(arr,arr+n);

float w=(arr[0]*a)/total;
ll i=n-1,count=0;
while(w<b)
{
	total=total-arr[i];
	count++;
	w=(arr[0]*a)/total;
}
cout<<count<<endl;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n,a,b,total=0;
cin>>n>>a>>b;
ll arr[n];
for(ll i=0;i<n;i++)
{
cin>>arr[i];
total+=arr[i];
}
float w=(arr[0]*a)/total;
ll i=n-1,count=0;
while(w<b)
{
	total=total-arr[i];
	count++;
	w=(arr[0]*a)/total;
}
cout<<count<<endl;

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n,a,b,total=0;
cin>>n>>a>>b;
ll arr[n];
for(ll i=0;i<n;i++)
{
cin>>arr[i];
total+=arr[i];
}
sort(arr,arr+n);
reverse(arr,arr+n);
float w=(arr[0]*a)/total;
ll i=n-1,count=0;
while(w<b)
{
	total=total-arr[i];
	count++;
	w=(arr[0]*a)/total;
}
cout<<count<<endl;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n,a,b,total=0;
cin>>n>>a>>b;
ll arr[n];
for(ll i=0;i<n;i++)
{
cin>>arr[i];
total+=arr[i];
}
sort(arr,arr+n);
reverse(arr,arr+n);

float w=(arr[0]*a)/total;
ll i=n-1,count=0;
while(w<b)
{
	total=total-arr[i];
	count++;
	w=(arr[0]*a)/total;
}
cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main()
{
    long long int n,a,b;
    cin>>n>>a>>b;
    long long int s[n],i,sum=0,m,count=0;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
        sum+=s[i];
    }
    m=s[0];
    if(a==b)
        cout<<n-1<<"\n";
    else if((a*m)/sum>=b)
    {
        cout<<0<<"\n";
    }
    else
    {
        sort(s,s+n);
        for(i=1;i<n;i++)
        {
            if(a*m/(sum-s[i])>=b)
            {
                count++;
                break;
            }
            else
            {
                sum=sum-s[i];
                count++;
            }
        }
        cout<<count<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main()
{
    long long int n,a,b;
    cin>>n>>a>>b;
    long long int s[n],i,sum=0,m,count=0;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
        sum+=s[i];
    }
    m=s[0];
    if(a==b)
        cout<<n-1<<"\n";
    else if((a*m)/sum>=b)
    {
        cout<<0<<"\n";
    }
    else
    {
        sort(s+1,s+n);
        for(i=n-1;i>=1;i--)
        {
            if(a*m/(sum-s[i])>=b)
            {
                count++;
                break;
            }
            else
            {
                sum=sum-s[i];
                count++;
            }
        }
        cout<<count<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main()
{
    long long int n,a,b;
    cin>>n>>a>>b;
    long long int s[n],i,sum=0,m,count=0;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
        sum+=s[i];
    }
    m=s[0];
    if(a==b)
        cout<<n-1<<"\n";
    else if((a*m)/sum>=b)
    {
        cout<<0<<"\n";
    }
    else
    {
        sort(s,s+n);
        for(i=1;i<n;i++)
        {
            if(a*m/(sum-s[i])>=b)
            {
                count++;
                break;
            }
            else
            {
                count++;
            }
        }
        cout<<count<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main()
{
    long long int n,a,b;
    cin>>n>>a>>b;
    long long int s[n],i,sum=0,m,count=0;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
        sum+=s[i];
    }
    m=s[0];
    if(a==b)
        cout<<n-1<<"\n";
    else if((a*m)/sum>=b)
    {
        cout<<0<<"\n";
    }
    else
    {
        sort(s+1,s+n);
        for(i=1;i<n;i++)
        {
            if(a*m/(sum-s[i])>=b)
            {
                count++;
                break;
            }
            else
            {
                sum=sum-s[i];
                count++;
            }
        }
        cout<<count<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main()
{
    long long int n,a,b;
    cin>>n>>a>>b;
    long long int s[n],i,sum=0,m,count=0;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
        sum+=s[i];
    }
    m=s[0];
    if(a==b)
        cout<<n-1<<"\n";
    else if((a*m)/sum>=b)
    {
        cout<<0<<"\n";
    }
    else
    {
        sort(s+1,s+n);
        for(i=1;i<n;i++)
        {
            if(a*m/(sum-s[i])>=b)
            {

                if(a*m/(sum-s[i])==b)
                    count++;
                break;
            }
            else
            {
                sum=sum-s[i];
                count++;
            }
        }
        cout<<count<<"\n";
    }
}


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

int s[11000];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int i, j, k, n, a, b;
    double flow;

    cin>>n>>a>>b;
    for(i=1;i<=n;i++)
        cin>>s[i];
    sort(s+2, s+n+1);
    for(i=3;i<=n;i++)
        s[i] += s[i-1];
    for(i=2;i<=n;i++){
        flow = (s[1]*a*1.0)/(s[1]+s[n]-s[i]);
        if(flow>=b){
            cout<<i-1<<endl;
            return 0;
        }
    }

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll i, j, k, n, a, b, val, first;
    vector<ll> s;
    double flow;

    cin>>n>>a>>b;
    cin>>first;
    for(i=0;i<n-1;i++){
        cin>>val;
        s.push_back(val);
    }
    sort(s.begin(), s.end());
    reverse(s.begin(), s.end());
    for(i=1;i<s.size();i++)
        s[i] += s[i-1];

    flow = (first*a*1.0)/(first+s[n-2]);
    if(flow>=b){
        cout<<0<<endl;
        return 0;
    }
    for(i=0;i<n-1;i++){
        flow = (first*a*1.0)/(first+s[n-2]-s[i]);
        if(flow>=b){
            cout<<i+1<<endl;
            return 0;
        }
    }
    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll i, j, k, n, a, b, val, first, sum=0;
    vector<ll> s;
    double flow;

    cin>>n>>a>>b;
    cin>>first;
    for(i=0;i<n-1;i++){
        cin>>val;
        s.push_back(val);
        sum += val;
    }
    sort(s.begin(), s.end());
    reverse(s.begin(), s.end());
    for(i=1;i<s.size();i++)
        s[i] += s[i-1];

    flow = (first*a*1.0)/(first+sum);
    if(flow>=b){
        cout<<0<<endl;
        return 0;
    }
    for(i=0;i<n-1;i++){
        flow = (first*a*1.0)/(first+s[n-2]-s[i]);
        if(flow>=b){
            cout<<i+1<<endl;
            return 0;
        }
    }
    return 0;
}


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

int s[11000];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int i, j, k, n, a, b;
    double flow;

    cin>>n>>a>>b;
    for(i=1;i<=n;i++)
        cin>>s[i];
    sort(s+2, s+n+1);
    for(i=3;i<=n;i++)
        s[i] += s[i-1];

    flow = (s[1]*a*1.0)/(s[1]+s[n]);
    if(flow>=b){
        cout<<0<<endl;
        return 0;
    }
    for(i=2;i<=n;i++){
        flow = (s[1]*a*1.0)/(s[1]+s[n]-s[i]);
        if(flow>=b){
            cout<<i-1<<endl;
            return 0;
        }
    }

    return 0;
}


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

int main()
{

 long long n,a,b;
 cin>>n>>a>>b;
 long long arr[n];
 long long sum=0;
 for(long long i=0;i<n;i++){
     cin>>arr[i];
     sum+=arr[i];
 }
 //float p=(float)(arr[0]*a)/(float)sum;
long long count=0;

 sort(arr+1,arr+n);

	while(arr[0]*a < sum*b)
	{
		sum-=arr[n-1-count];
		count++;
	}
	cout<<count;

 }


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

int main()
{

 int n,a,b;
 cin>>n>>a>>b;
 int arr[n];
 int sum=0;
 for(int i=0;i<n;i++){
     cin>>arr[i];
     sum+=arr[i];
 }
 float p=(float)(arr[0]*a)/(float)sum;
int count=0;

 sort(arr+1,arr+n);

	while(arr[0]*a < sum*b)
	{
		sum-=arr[n-1-count];
		count++;
	}
	cout<<count;

 }


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

int main()
{

 int n,a,b;
 cin>>n>>a>>b;
 int arr[n];
 int sum=0;
 for(int i=0;i<n;i++){
     cin>>arr[i];
     sum+=arr[i];
 }
 float p=(float)(arr[0]*a)/(float)sum;
int count=0;
 if(p>b) cout<<0<<endl;
 sort(arr+1,arr+n);
 for(int i=1;i<n;i++){
     while(p<b){
         sum-=arr[i];
         p=(float)(arr[0]*a)/(float)sum;
         count++;
     }
 }
 cout<<count;
}


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

int main()
{

 int n,a,b;
 cin>>n>>a>>b;
 int arr[n];
 int sum=0;
 for(int i=0;i<n;i++){
     cin>>arr[i];
     sum+=arr[i];
 }
 float p=(float)(arr[0]*a)/(float)sum;
int count=0;

 sort(arr+1,arr+n);
 for(int i=1;i<n;i++){
     while(p<b){
         sum-=arr[i];
         p=(float)(arr[0]*a)/(float)sum;
         count++;
     }
 }
 cout<<count;
}


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

int main()
{

 int n,a,b;
 cin>>n>>a>>b;
 int arr[n];
 int sum=0;
 for(int i=0;i<n;i++){
     cin>>arr[i];
     sum+=arr[i];
 }
 float p=(float)(arr[0]*a)/(float)sum;
int count=0;

 sort(arr+1,arr+n);
 for(int i=n-1;i>=0;i--){
     while(p<b){
         sum-=arr[i];
         p=(float)(arr[0]*a)/(float)sum;
         count++;
     }
 }
 cout<<count;
}


#include <iostream>
#include <vector>
#include <algorithm>

int main() {
	int n, a, b;
	std::cin >> n;
	std::cin >> a;
	std::cin >> b;
	std::vector<int> s(n);

	uint64_t S = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> s[i];
		S += s[i];
	}

	if (S * b <= s[0] * a || n == 1) {
		std::cout << "0";
		return 0;
	}
	else if (n == 2) {
		std::cout << "1";
		return 0;
	}
	std::sort(s.begin() + 1, s.end());

	int i = 1;
	while (i < n) {
		S -= s[n - i - 1];
		if (S * b <= s[0] * a) {
			std::cout << i;
			return 0;
		}
		i++;
	}
	std::cout << i - 1;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

int main() {
	int n, a, b;
	std::cin >> n;
	std::cin >> a;
	std::cin >> b;
	std::vector<int> s(n);

	float S = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> s[i];
		S += s[i];
	}

	if (s[0] * a / S >= b || n == 1) {
		std::cout << "0";
		return 0;
	}
	std::sort(s.begin() + 1, s.end());

	int i = 1;
	while (i < n) {
		S -= s[n - i - 1];
		if (s[0] * a / S >= b) {
			std::cout << i;
			return 0;
		}
		i++;
	}
	std::cout << i - 1;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

int main() {
	int n, a, b;
	std::cin >> n;
	std::cin >> a;
	std::cin >> b;
	std::vector<int> s(n);

	uint64_t S = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> s[i];
		S += s[i];
	}
	auto t = s[0] * a;
	if (S * b <= t || n == 1) {
		std::cout << 0;
		return 0;
	} else if (n == 2) {
		std::cout << 1;
		return 0;
	} else if (a == b) {
		std::cout << n - 1;
		return 0;
	}

	std::sort(s.begin() + 1, s.end());

	for (int i = 1; i < n; i++) {
		S -= s[n - i];
		if (S * b <= t || i == n - 1) {
			std::cout << i;
			return 0;
		}
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

int main() {
	int n, a, b;
	std::cin >> n;
	std::cin >> a;
	std::cin >> b;
	std::vector<int> s(n);

	float S = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> s[i];
		S += s[i];
	}

	if ((s[0] * a / S >= b) || (n == 1)) {
		std::cout << "0";
		return 0;
	}
	std::sort(s.begin() + 1, s.end());

	int i = 1;
	while (1) {
		S -= s[n - i - 1];
		if (s[0] * a / S >= b) {
			std::cout << i;
			return 0;
		}
		i++;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>

int main() {
	int n, a, b;
	std::cin >> n;
	std::cin >> a;
	std::cin >> b;
	std::vector<int> s(n);

	float S = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> s[i];
		S += s[i];
	}
	if (s[0] * a / S >= b) {
		std::cout << "0";
		return 0;
	}
	std::sort(s.begin() + 1, s.end());

	int i = 1;
	while (1) {
		S -= s[n - i - 1];
		if (s[0] * a / S >= b) {
			std::cout << i;
			return 0;
		}
		i++;
	}
}


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

int find(float k){
	int ans = p.size()-1;
	int l = 0, r = p.size()-1;
	while(l<=r){
		int mid = l + (r-l)/2;
		if(p[mid]>=k){
			ans = min(mid,ans);
			r = mid-1;
		}
		else{
			l = mid+1;
		}
	}
	int n = p.size();
	return min(ans,n-1);
}
int main() {
	// your code goes here
	int n,a,b,i,r;
	p.push_back(0);
	scanf("%d %d %d",&n,&a,&b);
	scanf("%d",&r);
	for(int x=0;x<n-1;x++){
		scanf("%d",&i);
		p.push_back(p.back()+i);
	}
	float k = p.back()+r - ((float(r*a))/b);
	k+= 0.00001;
	// cout<<k<<" ";
	cout<<find(k);
	return 0;
}


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

int find(float k){
	int ans = p.size()-1;
	int l = 0, r = p.size()-1;
	while(l<=r){
		int mid = l + (r-l)/2;
		if(p[mid]>=k){
			ans = min(mid,ans);
			r = mid-1;
		}
		else{
			l = mid+1;
		}
	}
	int n = p.size();
	return min(ans,n-1);
}
int main() {
	// your code goes here
	int n,a,b,i,r;
	p.push_back(0);
	scanf("%d %d %d",&n,&a,&b);
	scanf("%d",&r);
	for(int x=0;x<n-1;x++){
		scanf("%d",&i);
		p.push_back(p.back()+i);
	}
	float k = p.back()+r - ((float(r*a))/b);
	k+= 0.1;
	// cout<<k<<" ";
	cout<<find(k);
	return 0;
}


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

int find(float k){
	int ans = p.size()-1;
	int l = 0, r = p.size()-1;
	while(l<=r){
		int mid = l + (r-l)/2;
		if(p[mid]>=k){
			ans = min(mid,ans);
			r = mid-1;
		}
		else{
			l = mid+1;
		}
	}
	int n = p.size();
	return min(ans,n-1);
}
int main() {
	// your code goes here
	int n,a,b,i,r;
	p.push_back(0);
	scanf("%d %d %d",&n,&a,&b);
	scanf("%d",&r);
	for(int x=0;x<n-1;x++){
		scanf("%d",&i);
		p.push_back(p.back()+i);
	}
	float k = p.back()+r - ((float(r*a))/b);
	// k+=0.00001;
	// cout<<k<<" ";
	cout<<find(k);
	return 0;
}


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

int find(float k){
	int ans = p.size()-1;
	int l = 0, r = p.size()-1;
	while(l<=r){
		int mid = l + (r-l)/2;
		if(p[mid]>=k){
			ans = min(mid,ans);
			r = mid-1;
		}
		else{
			l = mid+1;
		}
	}
	int n = p.size();
	return min(ans,n-1);
}
int main() {
	// your code goes here
	int n,a,b,i,r;
	p.push_back(0);
	scanf("%d %d %d",&n,&a,&b);
	scanf("%d",&r);
	for(int x=0;x<n-1;x++){
		scanf("%d",&i);
		p.push_back(p.back()+i);
	}
	float k = p.back()+r - ((float(r*a))/b);
	k+= 0.0001;
	// cout<<k<<" ";
	cout<<find(k);
	return 0;
}


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

int find(float k){
	int ans = p.size()-1;
	int l = 0, r = p.size()-1;
	while(l<=r){
		int mid = l + (r-l)/2;
		if(p[mid]>=k){
			ans = min(mid,ans);
			r = mid-1;
		}
		else{
			l = mid+1;
		}
	}
	return ans;
}

int main() {
	// your code goes here
	int n,a,b,i,r;
	p.push_back(0);
	vector<int> l;
	scanf("%d %d %d",&n,&a,&b);
	scanf("%d",&r);
	for(int x=0;x<n-1;x++){
		scanf("%d",&i);
		l.push_back(i);
	}
	sort(l.begin(),l.end());
	for(int x=0;x<l.size();x++){
		i = l[l.size()-1-x];
		p.push_back(p.back()+i);
	}
	float k = p.back()+r - ((float(r*a))/b);
	// k+=0.00001;
	// cout<<k<<" "<<p.back()<<" ";
	cout<<find(k);
	return 0;
}


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

int find(int k){
	vector<long long int>::iterator ans = lower_bound(p.begin(),p.end(),k);
	return ans-p.begin();
}
int main() {
	// your code goes here
	int n,a,b,i,r;

	p.push_back(0);
	scanf("%d %d %d",&n,&a,&b);
	scanf("%d",&r);
	for(int x=0;x<n-1;x++){
		scanf("%d",&i);
		p.push_back(((p.back()/10)+i)*10);
	}
	i=0;
	int k  = (((p.back()/10)+r)*b - (r*a));
	if(k%b>0) i=1;
	k/=b;
	if(k<=0){
		cout<<0;
		return 0;
	}
	// cout<<i<<" ";
	cout<<find(((k+i)*10)+1)-1;
	return 0;
}


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

int find(float k){
	int ans = p.size()-1;
	int l = 0, r = p.size()-1;
	while(l<=r){
		int mid = l + (r-l)/2;
		if(p[mid]>=k){
			ans = min(mid,ans);
			r = mid-1;
		}
		else{
			l = mid+1;
		}
	}
	int n = p.size();
	return ans;
}
int main() {
	// your code goes here
	int n,a,b,i,r;
	p.push_back(0);
	scanf("%d %d %d",&n,&a,&b);
	scanf("%d",&r);
	for(int x=0;x<n-1;x++){
		scanf("%d",&i);
		p.push_back(p.back()+i);
	}
	float k = p.back()+r - ((float(r*a))/b);
	// k+=0.00001;
	// cout<<k<<" ";
	cout<<find(k);
	return 0;
}


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

int find(int k){
	vector<int>::iterator ans = lower_bound(p.begin(),p.end(),k);
	return ans-p.begin();
}
int main() {
	// your code goes here
	int n,a,b,i,r;

	p.push_back(0);
	scanf("%d %d %d",&n,&a,&b);
	scanf("%d",&r);
	for(int x=0;x<n-1;x++){
		scanf("%d",&i);
		p.push_back(p.back()+i);
	}
	int k  = (p.back()+r) - (((r*a)/b) + ((((r*a)%b)>0)? 1:0));
	cout<<find(k);
	return 0;
}


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

int find(int k){
	vector<long long int>::iterator ans = lower_bound(p.begin(),p.end(),k);
	return ans-p.begin();
}
int main() {
	// your code goes here
	int n,a,b,i,r;

	p.push_back(0);
	scanf("%d %d %d",&n,&a,&b);
	scanf("%d",&r);
	for(int x=0;x<n-1;x++){
		scanf("%d",&i);
		p.push_back(((p.back()/10)+i)*10);
	}
	i=0;
	int k  = (((p.back()/10)+r)*b - (r*a));
	k = max(k,0);
	if(k%b>0) i=1;
	k/=b;
	// cout<<i<<" ";
	cout<<find(((k+i)*10)+1)-1;
	return 0;
}


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

int find(int k){
	vector<int>::iterator ans = lower_bound(p.begin(),p.end(),k);
	return ans-p.begin();
}
int main() {
	// your code goes here
	int n,a,b,i,r;

	p.push_back(0);
	scanf("%d %d %d",&n,&a,&b);
	scanf("%d",&r);
	for(int x=0;x<n-1;x++){
		scanf("%d",&i);
		p.push_back(p.back()+i);
	}
	int k  = (p.back()+r) - ((r*a)/b);
	cout<<find(k);
	return 0;
}


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

int find(int k){
	vector<int>::iterator ans = lower_bound(p.begin(),p.end(),k);
	return ans-p.begin();
}
int main() {
	// your code goes here
	int n,a,b,i,r;

	p.push_back(0);
	scanf("%d %d %d",&n,&a,&b);
	scanf("%d",&r);
	for(int x=0;x<n-1;x++){
		scanf("%d",&i);
		p.push_back(((p.back()/10)+i)*10);
	}
	i=0;
	int k  = (((p.back()/10)+r)*b - (r*a))/b;
	// if(k%b>0) i=1;
	cout<<find(k*10);
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n,lim,a,b,s,somma = 0, l[100001],i;

	cin >> n >> a >> b;
	cin >> s;
	if (n ==1) {
		cout << 0;
		return 0;
	}
	for (int i=0;i<n-1;i++)
		cin >> l[i];
	sort(l,l+n-1);
	lim = s*a/b -s;
	i = 0;
	while ((i < n-1) && (lim > somma)) {
		somma += l[i];
		i++;
	}
	cout << n-1-i;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n,lim,a,b,s,somma = 0, l[100001],i;

	cin.tie(0);
	cin.sync_with_stdio(0);
	cout.tie(0);
	cout.sync_with_stdio(0);
	cin >> n >> a >> b;
	cin >> s;
	if (n ==1) {
		cout << 0;
		return 0;
	}
	for (int i=0;i<n-1;i++)
		cin >> l[i];
	sort(l,l+n-1);
	lim = s*a/b -s;
	i = 0;
	while ((i < n-1) && (lim > somma)) {
		somma += l[i];
		i++;
	}
	if (lim >= somma)
		cout << n-1-i;
	else
		cout << n-i;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n,lim,a,b,s,somma = 0, l[100001],i;

	cin >> n >> a >> b;
	cin >> s;
	if (n ==1) {
		cout << 0;
		return 0;
	}
	for (int i=0;i<n-1;i++)
		cin >> l[i];
	sort(l,l+n-1);
	lim = s*a/b -s;
	i = 0;
	while ((i < n-1) && (lim > somma)) {
		somma += l[i];
		i++;
	}
	if (lim >= somma)
		cout << n-1-i;
	else
		cout << n-i;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n, a,b, s[100001], limite, tot = 0, x,i;

	cin.tie(0);
	cin.sync_with_stdio(0);
	cout.tie(0);
	cin >> n >> a >> b;
	cin >> x;
	for (int i=0;i<n-1;i++)
		cin >> s[i];
	limite = x*(a/b -1);
	sort(s,s+n-1);
	i = 0;
	while ((tot < limite) && (i <n)) {
		tot += s[i];
		i++;
	}
	if (i ==n)
		cout << 0;
	else
		cout << n-1 -i;
	return 0;
}


#include<iostream>
#define ll long long
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = 105+7;
int n;
ll  a, b, s[maxn];
ll sum = 0;

int main()
{
    scanf("%d%lld%lld", &n,&a,&b);
    for(int i = 0; i < n; i++) scanf("%lld",&s[i]), sum += s[i];
    ll k = s[0]*a;
    int num = 0;
    sort(s+1, s+n);
    if(k >= b*sum) printf("%d\n",num);
    else {
       for(int i = n - 1; i > 0; i--)
       {
           sum -= s[i]; num++;
           if(k >= b*sum) {
                printf("%d\n",num);
                break;
           }
       }
    }
    return 0;
}


#include<iostream>
#define ll long long
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = 1e5+7;
int n;
ll  a, b, s[maxn];
ll sum = 0;

int main()
{
    scanf("%d%lld%lld", &n,&a,&b);
    for(int i = 0; i < n; i++) scanf("%lld",&s[i]), sum += s[i];
    ll k = s[0]*a;
    int num = 0;
    sort(s+1, s+n);
    if(k >= b*sum) printf("%d\n",num);
    else {
       for(int i = n - 1; i > 0; i--)
       {
           sum -= s[i]; num++;
           if(k >= b*sum) {
                printf("%d\n",num);
                break;
           }
       }
    }
    return 0;
}


#include<iostream>
#define ll long long
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = 105+7;
int n;
ll  a, b, s[maxn];
ll sum = 0;

int main()
{
    scanf("%d%lld%lld", &n,&a,&b);
    for(int i = 0; i < n; i++) scanf("%lld",&s[i]), sum += s[i];
    ll k = s[0]*a, num = 0;
    sort(s+1, s+n);
    if(k >= b*sum) printf("%d\n",num);
    else {
       for(int i = n - 1; i >= 1; i--)
       {
           sum -= s[i];
           num++;
           if(k >= b*sum) {
                printf("%d\n",num);
                break;
           }
       }
    }
    return 0;
}


#include<iostream>
#define ll long long
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = 107;
int n, a, b, s[maxn];
ll sum = 0;

int main()
{
    scanf("%d%d%d", &n,&a,&b);
    for(int i = 0; i < n; i++) scanf("%d",&s[i]), sum += s[i];
    ll k = s[0], num = 0;
    sort(s+1, s+n);
    if(k*a/sum >= b) printf("%d",num);
    else {
       for(int i = n - 1; i >= 1; i--)
       {
           sum -= s[i];
           num++;
           if(k*a/sum >= b) {
                printf("%d",num);
                break;
           }
       }
    }
    return 0;
}


#include<iostream>
#define ll long long
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = 105+7;
int n;
ll  a, b, s[maxn];
ll sum = 0;

int main()
{
    scanf("%d%lld%lld", &n,&a,&b);
    for(int i = 0; i < n; i++) scanf("%lld",&s[i]), sum += s[i];
    ll k = s[0]*a, num = 0;
    sort(s+1, s+n);
    if(k >= b*sum) printf("%lld\n",num);
    else {
       for(int i = n - 1; i > 0; i--)
       {
           sum -= s[i];
           num++;
           if(k >= b*sum) {
                printf("%lld\n",num);
                break;
           }
       }
    }
    return 0;
}


#include<iostream>
#define ll long long
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = 105+7;
int n;
ll  a, b, s[maxn];
ll sum = 0;

int main()
{
    scanf("%d%lld%lld", &n,&a,&b);
    for(int i = 0; i < n; i++) scanf("%lld",&s[i]), sum += s[i];
    ll k = s[0], num = 0;
    sort(s+1, s+n);
    if(k*a/sum >= b) printf("%d\n",num);
    else {
       for(int i = n - 1; i >= 1; i--)
       {
           sum -= s[i];
           num++;
           if(k*a/sum >= b) {
                printf("%d\n",num);
                break;
           }
       }
    }
    return 0;
}


#include<iostream>
#define ll long long
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = 105+7;
int n, a, b, s[maxn];
ll sum = 0;

int main()
{
    scanf("%d%d%d", &n,&a,&b);
    for(int i = 0; i < n; i++) scanf("%d",&s[i]), sum += s[i];
    ll k = s[0], num = 0;
    sort(s+1, s+n);
    if(k*a/sum >= b) printf("%d",num);
    else {
       for(int i = n - 1; i >= 1; i--)
       {
           sum -= s[i];
           num++;
           if(k*a/sum >= b) {
                printf("%d",num);
                break;
           }
       }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, A, B, i, hole, sum=0, sum1=0, count1=0;
    cin >> n >> A >> B;
    int arr[n];

    for(i=0; i<n; i++)
    {
        cin >> arr[i];
        sum = sum + arr[i];
    }
    sort(arr+1, arr+n, greater<int>());

    hole = (arr[0]*A)/sum;

    if(hole>=B)
    {
        cout<< "0";
    }

    else
    {
        for(i=1; i<n; i++)
        {
            sum = sum - arr[i];

            hole = (arr[0]*A)/sum;

            if(hole>=B)
            {
                cout << i;
                break;
            }
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, A, B, i, hole, sum=0, sum1=0, count1=0;
    cin >> n >> A >> B;
    int arr[n];

    for(i=0; i<n; i++)
    {
        cin >> arr[i];
        sum = sum + arr[i];
    }

    for(i=0; i<n; i++)
    {
        sum1 = sum1 + arr[i];
        hole = (arr[0]*A)/sum1;

        if(hole>=B)
        {
            count1++;
        }

        else
        {
            break;
        }
    }

    //cout << count1 <<  endl;

    cout << n-count1;

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, A, B, i, hole, sum=0, sum1, count1=0, sum2, hole2;
    cin >> n >> A >> B;
    int arr[n];

    for(i=0; i<n; i++)
    {
        cin >> arr[i];
        sum = sum + arr[i];
    }

    sum1 = sum;

    hole = (arr[0]*A)/sum1;

    if(hole>=B)
    {
        cout << "0";
    }

    else
    {
        for(i=1; i<n; i++)
        {
            sum2 = sum - arr[i];
            sum1 = sum1 - arr[i];

            hole = (arr[0]*A)/sum2;

            if(hole>=B)
            {
                cout<< "1";
                break;
            }

            else
            {
                hole2 = (arr[0]*A)/sum1;

                if(hole2>=B)
                {
                    cout << i;
                    break;
                }
            }
        }

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, A, B, i, hole, sum=0, sum1, count1=0;
    cin >> n >> A >> B;
    int arr[n];

    for(i=0; i<n; i++)
    {
        cin >> arr[i];
        sum = sum + arr[i];
    }
    sum1 = sum;

    for(i=0; i<n; i++)
    {
        hole = (arr[i] * A)/sum1;

        if(i!=0)
        {
            count1++;
        }

        if(hole >=B)
        {
           cout << count1;
           break;
        }

        else
        {
            sum1 = sum1 - arr[i];
        }
    }
    return 0;

}


#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int a[1000 * 100 + 100];

int main(){
    int n, S = 0, f, A, B;
    cin >> n >> A >> B >> f;
    S = f;
    for (int i = 0; i < n - 1; i++){
        cin >> a[i];
        S += a[i];
    }
    sort(a, a + n - 1);
    int Sp = 0;
    for (int i = 0; i < n - 1; i++){
        if ( ll(1ll * (A * f))  >= ll(1ll * B * (S - Sp)) ){
            cout << i;
            return 0;}
        Sp += a[i];
    }
    cout << n - 1 << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define newline '\n'
const int maxrange =2222;
int n , m;
ll a[2 *maxrange];
ll b[2 *maxrange];
map <ll , int>freq1 , freq2 ,store , visit;
set<ll>st;
ll ans =1e9;
bool solve(ll x){
    visit.clear();
    for(int i =0 ; i <n ; i ++){
        visit[(a[i] +x) %m] ++;
    }
    bool found =0;
    for(int i =0 ; i <n ; i ++){
        if(visit[b[i]] !=store[b[i] %m]){
            found =1;
            break;
        }
    }
    if(found) return 0;
    else return 1;
}
main(){
    ios :: sync_with_stdio(false);
    cin.tie(false);
    cout.tie(false);
    cin >>n >>m;
    for(int i =0 ; i <n ; i ++){
        cin >>a[i];
        //a[i] =a[i] %m;
        freq1[a[i]] ++;
    }
    for(int i =0 ; i <n ; i ++){
        cin >>b[i];
        //b[i] =b[i] %m;
        store[b[i]] ++;
        freq2[b[i]] ++;
    }
    for(auto temp1 :freq1){
        for(auto temp2 :freq2){
            if(temp1.second == temp1.second){
                if(temp1.first <=temp2.first){
                    st.insert(temp2.first - temp1.first);
                }else{
                    st.insert((temp2.first +m - temp1.first) %m);
                }
            }
        }
    }
    for(auto x :st){
        if(solve(x)){
            ans =min(ans , x);
            break;
        }
    }
    cout <<ans <<newline;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define newline '\n'
const int maxrange =2222;
int n , m;
ll a[2 *maxrange];
ll b[2 *maxrange];
map <ll , int>store , visit;
set<ll>st;
ll ans =1e9;
bool solve(ll x){
    visit.clear();
    for(int i =0 ; i <n ; i ++){
        visit[(a[i] +x) %m] ++;
    }
    bool found =0;
    for(int i =0 ; i <n ; i ++){
        if(visit[b[i]] !=store[b[i]]){
            found =1;
            break;
        }
    }
    if(found) return 0;
    else return 1;
}
main(){
    ios :: sync_with_stdio(false);
    cin.tie(false);
    cout.tie(false);
    cin >>n >>m;
    for(int i =0 ; i <n ; i ++){
        cin >>a[i];
        a[i] =a[i] %m;
    }
    for(int i =0 ; i <n ; i ++){
        cin >>b[i];
        b[i] =b[i] %m;
        store[b[i]] ++;
    }
    sort(a , a +n);
    sort(b , b +n);
    for(int i =0 ; i <n ; i ++){
        for(int j =0 ; j <n ; j ++){
            st.insert(abs(a[i] -b[i]));
        }
    }
    for(auto x :st){
        if(solve(x)){
            ans =min(ans , x);
            break;
        }
    }
    cout <<ans <<newline;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define newline '\n'
const int maxrange =2222;
int n , m;
ll a[2 *maxrange];
ll b[2 *maxrange];
map <ll , int>store , visit;
set<int>st;
ll ans;
bool solve(int x){
    visit.clear();
    for(int i =0 ; i <n ; i ++){
        visit[(a[i] +x) %m] ++;
    }
    bool found =0;
    for(int i =0 ; i <n ; i ++){
        if(visit[b[i]] !=store[b[i]]){
            found =1;
            break;
        }
    }
    if(found) return 0;
    else return 1;
}
main(){
    ios :: sync_with_stdio(false);
    cin.tie(false);
    cout.tie(false);
    cin >>n >>m;
    for(int i =0 ; i <n ; i ++){
        cin >>a[i];
        a[i] =a[i] %m;
    }
    for(int i =0 ; i <n ; i ++){
        cin >>b[i];
        //b[i] =b[i] %m;
        store[b[i]] ++;
    }
    sort(a , a +n);
    sort(b , b +n);
    for(int i =0 ; i <n ; i ++){
        st.insert(abs(a[i] -b[i]));
    }
    for(auto x :st){
        if(solve(x)){
            ans =x;
            break;
        }
    }
    cout <<ans <<newline;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define newline '\n'
const int maxrange =2222;
int n , m;
int a[2 *maxrange];
int b[2 *maxrange];
map <int , int>freq1 , freq2 ,store , visit;
set<int>st;
int ans =1e9;
bool solve(ll x){
    visit.clear();
    for(int i =0 ; i <n ; i ++){
        visit[(a[i] +x) %m] ++;
    }
    bool found =0;
    for(int i =0 ; i <n ; i ++){
        if(visit[b[i]] !=store[b[i] %m]){
            found =1;
            break;
        }
    }
    if(found) return 0;
    else return 1;
}
main(){
    ios :: sync_with_stdio(false);
    cin.tie(false);
    cout.tie(false);
    cin >>n >>m;
    for(int i =0 ; i <n ; i ++){
        cin >>a[i];
        //a[i] =a[i] %m;
        freq1[a[i]] ++;
    }
    for(int i =0 ; i <n ; i ++){
        cin >>b[i];
        //b[i] =b[i] %m;
        freq2[b[i]] ++;
    }
    for(auto temp1 :freq1){
        for(auto temp2 :freq2){
            if(temp1.second == temp2.second){
                if(temp1.first <=temp2.first){
                    store[temp2.first - temp1.first] +=temp2.second;
                }else{
                    store[(temp2.first +m - temp1.first) %m] +=temp2.second;
                }
            }
        }
    }
    for(auto x :store){
        if(x.second ==n){
            ans =min(ans , x.first);
            break;
        }
        //cout <<x.first <<" " <<x.second <<newline;
    }
    cout <<ans <<newline;
    return 0;
}


/*  Never Island  */
/*deco loves Chino*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define int long long
int n,m,a[4010],b[4010],c[2010];
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
	}
	sort(a+1,a+n+1),sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
	{
		a[i+n]=a[i],b[i+n]=b[i];
	}
	int ans=0x3f3f3f3f;
	for(int i=1;i<=n;i++)
	{
		int del=(b[i]-a[1]+m)%m,fl=0;
		for(int j=2;j<=n;j++)
		{
			if((a[j]+del)%m!=b[i+j-1])
			{
				fl=1;
				break;
			}
		}
		if(!fl)
		{
			ans=min(ans,del);
			return 0;
		}
	}
	cout<<ans;

}


/*  Never Island  */
/*deco loves Chino*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define int long long
int n,m,a[2010],b[2010],c[2010];
unordered_map<int,int> mp;
int del[4000010],tot;
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	del[++tot]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int qwq;
			if(a[i]<=b[j])
			{
				qwq=b[j]-a[i];
			}
			else
			{
				qwq=(b[j]+m-a[i]);
			}
			if(!mp[qwq])
			{
				del[++tot]=qwq;
			}
			mp[qwq]=1;
		}
	}
	memcpy(c,a,sizeof(a));
	for(int i=1;i<=tot;i++)
	{
		for(int j=1;j<=n;j++)
		{
			a[j]=(a[j]+del[i])%m;
		}
		sort(a+1,a+n+1);
		int fl=0;
		for(int i=1;i<=n;i++)
		{
			if(a[i]!=b[i])
			{
				fl=1;
				break;
			}
		}
		memcpy(a,c,sizeof(c));
		if(fl)
		{
			continue;
		}
		else
		{
			cout<<del[i];
			return 0;
		}
	}
}


/*  Never Island  */
/*deco loves Chino*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define int long long
int n,m,a[4010],b[4010],c[2010];
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		a[i+n]=a[i];
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
		b[i+n]=b[i];
	}
	for(int i=1;i<n;i++)
	{
		int del=(b[i]-a[i]+m)%m,fl=0;
		for(int j=1;j<=n;j++)
		{
			if((a[i]+del)%m!=b[i+j-1])
			{
				fl=1;
				break;
			}
		}
		if(!fl)
		{
			cout<<del;
			return 0;
		}
	}

}


/*  Never Island  */
/*deco loves Chino*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define int long long
int n,m,a[2010],b[2010],c[2010];
unordered_map<int,int> mp;
int del[4000010],tot;
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	del[++tot]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int qwq;
			if(a[i]<b[j])
			{
				qwq=b[j]-a[i];
			}
			else
			{
				qwq=(b[j]+m-a[i]);
			}
			if(!mp[qwq])
			{
				del[++tot]=qwq;
			}
			mp[qwq]=1;
		}
	}
	memcpy(c,a,sizeof(a));
	for(int i=1;i<=tot;i++)
	{
		for(int j=1;j<=n;j++)
		{
			a[j]=(a[j]+del[i])%m;
		}
		sort(a+1,a+n+1);
		int fl=0;
		for(int i=1;i<=n;i++)
		{
			if(a[i]!=b[i])
			{
				fl=1;
				break;
			}
		}
		memcpy(a,c,sizeof(c));
		if(fl)
		{
			continue;
		}
		else
		{
			cout<<del[i];
			return 0;
		}
	}
}


/*  Never Island  */
/*deco loves Chino*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define int long long
int n,m,a[2010],b[2010],c[2010];
unordered_map<int,int> mp;
int del[4000010],tot;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	del[++tot]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int qwq;
			if(a[i]<=b[j])
			{
				qwq=b[j]-a[i];
			}
			else
			{
				qwq=(b[j]+m-a[i]);
			}
			if(!mp[qwq])
			{
				del[++tot]=qwq;
			}
			mp[qwq]=1;
		}
	}
	memcpy(c,a,sizeof(a));
	for(int i=1;i<=tot;i++)
	{
		for(int j=1;j<=n;j++)
		{
			a[j]=(a[j]+del[i])%m;
		}
		sort(a+1,a+n+1);
		int fl=0;
		for(int i=1;i<=n;i++)
		{
			if(a[i]!=b[i])
			{
				fl=1;
				break;
			}
		}
		memcpy(a,c,sizeof(c));
		if(fl)
		{
			continue;
		}
		else
		{
			cout<<del[i];
			return 0;
		}
	}
}


/*  Never Island  */
/*deco loves Chino*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define int long long
int n,m,a[2010],b[2010],c[2010];
unordered_map<int,int> mp;
int del[4000010],tot;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	del[++tot]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int qwq;
			if(a[i]<b[j])
			{
				qwq=b[j]-a[i];
			}
			else
			{
				qwq=(b[j]+m-a[i]);
			}
			if(!mp[qwq])
			{
				del[++tot]=qwq;
			}
			mp[qwq]=1;
		}
	}
	memcpy(c,a,sizeof(a));
	for(int i=1;i<=tot;i++)
	{
		for(int j=1;j<=n;j++)
		{
			a[j]=(a[j]+del[i])%m;
		}
		sort(a+1,a+n+1);
		int fl=0;
		for(int i=1;i<=n;i++)
		{
			if(a[i]!=b[i])
			{
				fl=1;
				break;
			}
		}
		memcpy(a,c,sizeof(c));
		if(fl)
		{
			continue;
		}
		else
		{
			cout<<del[i];
			return 0;
		}
	}
}


/*  Never Island  */
/*deco loves Chino*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define int long long
int n,m,a[4010],b[4010],c[2010];
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
	}
	sort(a+1,a+n+1),sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
	{
		a[i+n]=a[i],b[i+n]=b[i];
	}
	int ans=0x3f3f3f3f;
	for(int i=1;i<=n;i++)
	{
		int del=(b[i]-a[1]+m)%m,fl=0;
		for(int j=2;j<=n;j++)
		{
			if((a[j]+del)%m!=b[i+j-1])
			{
				fl=1;
				break;
			}
		}
		if(!fl)
		{
			ans=min(ans,del);
		}
	}
	cout<<ans;

}


/*  Never Island  */
/*deco loves Chino*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define int long long
int n,m,a[4010],b[4010],c[2010];
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
	}
	sort(a+1,a+n+1),sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
	{
		a[i+n]=a[i],b[i+n]=b[i];
	}
	for(int i=1;i<=n;i++)
	{
		int del=(b[i]-a[1]+m)%m,fl=0;
		for(int j=2;j<=n;j++)
		{
			if((a[j]+del)%m!=b[i+j-1])
			{
				fl=1;
				break;
			}
		}
		if(!fl)
		{
			cout<<del;
			return 0;
		}
	}

}


/*  Never Island  */
/*deco loves Chino*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
int n,m,a[2010],b[2010],c[2010];
unordered_map<int,int> mp;
int del[4000010],tot;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	del[++tot]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int qwq;
			if(a[i]<b[j])
			{
				qwq=b[j]-a[i];
			}
			else
			{
				qwq=(b[j]+m-a[i]);
			}
			if(!mp[qwq])
			{
				del[++tot]=qwq;
			}
			mp[qwq]=1;
		}
	}
	memcpy(c,a,sizeof(a));
	for(int i=1;i<=tot;i++)
	{
		for(int j=1;j<=n;j++)
		{
			a[j]=(a[j]+del[i])%m;
		}
		sort(a+1,a+n+1);
		int fl=0;
		for(int i=1;i<=n;i++)
		{
			if(a[i]!=b[i])
			{
				fl=1;
				break;
			}
		}
		memcpy(a,c,sizeof(c));
		if(fl)
		{
			continue;
		}
		else
		{
			cout<<del[i];
			return 0;
		}
	}
}


/*  Never Island  */
/*deco loves Chino*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define int long long
int n,m,a[4010],b[4010],c[2010];
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
	}
	sort(a+1,a+n+1),sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
	{
		a[i+n]=a[i],b[i+n]=b[i];
	}
	for(int i=1;i<n;i++)
	{
		int del=(b[i]-a[1]+m)%m,fl=0;
		for(int j=2;j<=n;j++)
		{
			if((a[j]+del)%m!=b[i+j-1])
			{
				fl=1;
				break;
			}
		}
		if(!fl)
		{
			cout<<del;
			return 0;
		}
	}

}


/*  Never Island  */
/*deco loves Chino*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
int n,m,a[2010],b[2010],c[2010];
unordered_map<int,int> mp;
int del[4000010],tot;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int qwq;
			if(a[i]<b[j])
			{
				qwq=b[j]-a[i];
			}
			else
			{
				qwq=(b[j]+m-a[i]);
			}
			if(!mp[qwq])
			{
				del[++tot]=qwq;
			}
			mp[qwq]=1;
		}
	}
	memcpy(c,a,sizeof(a));
	for(int i=1;i<=tot;i++)
	{
		for(int j=1;j<=n;j++)
		{
			a[j]=(a[j]+del[i])%m;
		}
		sort(a+1,a+n+1);
		int fl=0;
		for(int i=1;i<=n;i++)
		{
			if(a[i]!=b[i])
			{
				fl=1;
				break;
			}
		}
		memcpy(a,c,sizeof(c));
		if(fl)
		{
			continue;
		}
		else
		{
			cout<<del[i];
			return 0;
		}
	}
}


/*  Never Island  */
/*deco loves Chino*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define int long long
int n,m,a[2010],b[2010],c[2010];
unordered_map<int,int> mp;
int del[4000010],tot;
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	del[++tot]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int qwq;
			if(a[i]<=b[j])
			{
				qwq=b[j]-a[i];
			}
			else
			{
				qwq=(b[j]+m-a[i]);
			}
			if(!mp[qwq])
			{
				del[++tot]=qwq;
			}
			mp[qwq]=1;
		}
	}
	memcpy(c,a,sizeof(a));
	for(int i=1;i<=tot;i++)
	{
		for(int j=1;j<=n;j++)
		{
			a[j]=(a[j]+del[i])%m;
		}
		sort(a+1,a+n+1);
		int fl=0;
		for(int j=1;j<=n;j++)
		{
			if(a[j]!=b[j])
			{
				fl=1;
				break;
			}
		}
		memcpy(a,c,sizeof(c));
		if(fl)
		{
			continue;
		}
		else
		{
			cout<<del[i];
			return 0;
		}
	}
}


#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll m,n,a[2004],b[2005],c[2005];
ll minx;
int equal(ll x){
	for(ll i=1;i<=n;i++){
		c[i]=(a[i]+x)%m;
	}
	sort(c+1,c+n+1);
	for(ll j=1;j<=n;j++){
		if(c[j]!=b[j]) return 0;
		else break;
	}
	return 1;
}
int main(){
	scanf("%lld%lld",&n,&m);
	ll x;
	for(ll i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	for(ll i=n;i>=1;i--) scanf("%lld",&b[i]);
	sort(b+1,b+1+n);
	minx=m;
	for(ll i=1;i<=n;i++){
		x=(a[1]-b[i]+m)%m;
		if(equal(x)==1){
			minx=min(x,minx);
		}
	}
	printf("%lld\n",minx);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
long m,n,a[2004],b[2005],c[2005];
long minx;
int equal(long x){
	for(int i=1;i<=n;i++){
		c[i]=(a[i]+x)%m;
	}
	sort(c+1,c+n+1);
	for(int j=1;j<=n;j++){
		if(c[j]!=b[j]) return 0;
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	long x;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=n;i>=1;i--) scanf("%d",&b[i]);
	sort(b+1,b+1+n);
	minx=m;
	for(int i=1;i<=n;i++){
		x=(a[1]-b[i]+m)%m;
		if(equal(x)==1){
			minx=min(x,minx);
		}
	}
	printf("%d\n",minx);
	return 0;
}


#include<cstdio>
using namespace std;
int m,n,a[2004],b[2005];
int equal(int x){
	for(int i=1;i<=n;i++){
		a[i]+=x;
		if(a[i]%m!=b[i]){
			return 0;
		}
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	int x;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=n;i>=1;i--) scanf("%d",&b[i]);
	for(int i=0;;i++){
		if(equal(i)==1){
			x=i;
			break;
		}
	}
	printf("%d\n",x);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[2003],b[2003],c[2003];
void hzh()
{
	ll n,m,i,j,x,minx;
	scanf("%lld%lld",&n,&m);
	for(i=0;i<n;i++)
		scanf("%lld",&a[i]);
	for(i=0;i<n;i++)
		scanf("%lld",&b[i]);
	sort(b,b+n);
	minx=m;
	for(i=0;i<n;i++)
	{
		x=(a[0]-b[i]+m)%m;
		for(j=0;j<n;j++)
			c[j]=(a[j]+x)%m;
		sort(c,c+n);
		for(j=0;j<n;j++)
		{
			if(c[j]!=b[j])
				break;
			if(j==n-1)
					minx=min(x,minx);
		}
	}
	printf("%lld",minx);
	return;
}
int main()
{
	/*
	ll t;
	scanf("%lld",&t);
	while(t--)
	*/
    	hzh();
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
long m,n,a[2004],b[2005],c[2005];
long minx;
int equal(long x){
	for(int i=1;i<=n;i++){
		c[i]=(a[i]+x)%m;
	}
	sort(c+1,c+n+1);
	for(int j=1;j<=n;j++){
		if(c[j]!=b[j]) return 0;
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	long x;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=n;i>=1;i--) scanf("%d",&b[i]);
	sort(b+1,b+1+n);
	minx=m;
	for(int i=1;i<=n;i++){
		x=(a[0]-b[i]+m)%m;
		if(equal(x)==1){
			minx=min(x,minx);
		}
	}
	printf("%d\n",minx);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int m,n,a[2004],b[2005],c[2005];
int equal(int x){
	for(int i=1;i<=n;i++){
		c[i]=(a[i]+x)%m;
	}
	sort(c+1,c+n+1);
	for(int j=1;j<=n;j++){
		if(c[j]!=b[j]) return 0;
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	int x;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=n;i>=1;i--) scanf("%d",&b[i]);
	sort(b+1,b+1+n);
	for(int i=0;i<=m;i++){
		if(equal(i)==1){
			x=i;
			break;
		}
	}
	printf("%d\n",x);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
long long m,n,a[2004],b[2005],c[2005];
long minx;
int equal(long x){
	for(int i=1;i<=n;i++){
		c[i]=(a[i]+x)%m;
	}
	sort(c+1,c+n+1);
	for(int j=1;j<=n;j++){
		if(c[j]!=b[j]) return 0;
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	long x;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=n;i>=1;i--) scanf("%d",&b[i]);
	sort(b+1,b+1+n);
	minx=m;
	for(int i=1;i<=n;i++){
		x=(a[1]-b[i]+m)%m;
		if(equal(x)==1){
			minx=min(x,minx);
		}
	}
	printf("%ld\n",minx);
	return 0;
}


#include<cstdio>
using namespace std;
int m,n,a[2004],b[2005];
int equal(int x){
	for(int i=1;i<=n;i++){
		a[i]+=x;
		if(a[i]%m!=b[i]){
			return 0;
		}
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	int x;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=n;i>=1;i--) scanf("%d",&b[i]);
	for(int i=0;i<=m;i++){
		if(equal(i)==1){
			x=i;
			break;
		}
	}
	printf("%d\n",x);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long m,n;
long long a[20005],b[20005],c[20005];
int main(){
	long long x;
	long long minx;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	sort(b+1,b+1+n);
	minx=m;
	for(int i=1;i<=n;i++){
		x=(b[1]-a[i]+m)%m;
		for(int j=1;j<=n;j++){
			c[j]=(x+a[j]+m)%m;
		}
		sort(c+1,c+1+n);
		for(int j=1;j<=n;j++){
			if(c[j]!=b[j]){
				break;
			}
			if(j==n){
				minx=min(x,minx);
			}
		}
	}
	cout<<minx<<endl;
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll m,n,a[2004],b[2005],c[2005];
ll minx;
//int equal(ll x){
//	for(ll i=1;i<=n;i++){
//		c[i]=(a[i]+x)%m;
//	}
//	sort(c+1,c+n+1);
//	for(ll j=1;j<=n;j++){
//		if(c[j]!=b[j]) return 0;
//		else break;
//	}
//	return 1;
//}
int main(){
	scanf("%lld%lld",&n,&m);
	ll x;
	for(ll i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	for(ll i=n;i>=1;i--) scanf("%lld",&b[i]);
	sort(b+1,b+1+n);
	minx=m;
	for(ll i=1;i<=n;i++){
		x=(a[1]-b[i]+m)%m;
		for(ll j=1;j<=n;j++){
			c[j]=(a[j]+x)%m;
		}
		sort(c+1,c+1+n);
		for(ll j=1;j<=n;j++){
			if(c[j]!=b[j]){
				break;
			}
			if(j==n-1){
				minx=min(x,minx);
			}
		}
	}
	printf("%lld\n",minx);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
long long m,n,a[2004],b[2005],c[2005];
long minx;
int equal(long x){
	for(long i=1;i<=n;i++){
		c[i]=(a[i]+x)%m;
	}
	sort(c+1,c+n+1);
	for(long j=1;j<=n;j++){
		if(c[j]!=b[j]) return 0;
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	long x;
	for(int i=1;i<=n;i++){
		scanf("%ld",&a[i]);
	}
	for(int i=n;i>=1;i--) scanf("%ld",&b[i]);
	sort(b+1,b+1+n);
	minx=m;
	for(long i=1;i<=n;i++){
		x=(a[1]-b[i]+m)%m;
		if(equal(x)==1){
			minx=min(x,minx);
		}
	}
	printf("%ld\n",minx);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
long long m,n,a[2004],b[2005],c[2005];
long minx;
int equal(long x){
	for(int i=1;i<=n;i++){
		c[i]=(a[i]+x)%m;
	}
	sort(c+1,c+n+1);
	for(int j=1;j<=n;j++){
		if(c[j]!=b[j]) return 0;
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	long x;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=n;i>=1;i--) scanf("%d",&b[i]);
	sort(b+1,b+1+n);
	minx=m;
	for(int i=1;i<=n;i++){
		x=(a[1]-b[i]+m)%m;
		if(equal(x)==1){
			minx=min(x,minx);
		}
	}
	printf("%d\n",minx);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int m,n,a[2004],b[2005],c[2005];
int minx;
int equal(int x){
	for(int i=1;i<=n;i++){
		c[i]=(a[i]+x)%m;
	}
	sort(c+1,c+n+1);
	for(int j=1;j<=n;j++){
		if(c[j]!=b[j]) return 0;
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	int x;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=n;i>=1;i--) scanf("%d",&b[i]);
	sort(b+1,b+1+n);
	minx=m;
	for(int i=1;i<=n;i++){
		x=(a[0]-b[i]+m)%m;
		if(equal(x)==1){
			minx=min(x,minx);
		}
	}
	printf("%d\n",minx);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int m,n,a[2004],b[2005],c[2005];
int equal(int x){
	for(int i=1;i<=n;i++){
		c[i]=(a[i]+x)%m;
	}
	sort(c+1,c+n+1);
	for(int j=1;j<=n;j++){
		if(c[j]!=b[j]) return 0;
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	int x;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=n;i>=1;i--) scanf("%d",&b[i]);
	sort(b+1,b+1+n);
	for(int i=1;i<=n;i++){
		x=(a[0]-b[i]+m)%m;
		if(equal(x)==1){
			break;
		}
	}
	printf("%d\n",x);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);

/*
    VERIFICAR:
    - Corner cases
    - Estouro de variavel
    - Acesso indevido de memoria

*/

int main() {_
    int n, m;
    cin >> n >> m;
    int a, b;
    map<int, int> freqA;
    map<int, int> freqB;
    for(int I=0; I<n; I++) {
        cin >> a;
        freqA[a]++;
    }
    for(int I=0; I<n; I++) {
        cin >> b;
        freqB[b]++;
    }
    int valoresUnicos = 0;
    map<int, vector<int> > freqInvertidaA;
    map<int, vector<int> > freqInvertidaB;
    for(pair<int, int> f : freqA) {
        valoresUnicos++;
        freqInvertidaA[f.second].push_back(f.first);
    }
    for(pair<int, int> f : freqB) {
        freqInvertidaB[f.second].push_back(f.first);
    }
    freqA.clear();
    freqB.clear();
    map<int, set<int> > relacao;
    for(pair<int, vector<int> > fA : freqInvertidaA) {
        for(pair<int, vector<int> > fB : freqInvertidaB) {
            if(fB.first == fA.first) {
                for(int v1 : fA.second) {
                    for(int v2 : fB.second) {
                        int precisa = v2 - v1;
                        if(precisa < 0) {
                            precisa = (m - v1)+v2;
                        }
                        relacao[precisa].insert(v2);
                    }
                }
            }
        }
    }
    int possibilidade = 0x3f3f3f3f;
    for(pair<int, set<int> > r : relacao) {
        if(r.second.size() == valoresUnicos) {
            possibilidade = min(possibilidade, r.first);
        }
    }
    cout << possibilidade << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);

/*
    VERIFICAR:
    - Corner cases
    - Estouro de variavel
    - Acesso indevido de memoria

*/

int main() {_
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> b(n);
    for(int I=0; I<n; I++) {
        cin >> a[I];
    }
    for(int I=0; I<n; I++) {
        cin >> b[I];
    }
    sort(b.begin(), b.end());
    set<int> possib;
    for(int I=0; I<n; I++) {
        possib.insert((b[0]+m-a[I])%m);
    }
    for(int p : possib) {
        vector<int> temp(n);
        for(int J=0; J<n; J++) {
            temp[J] = (a[J]+p)%m;
        }
        sort(temp.begin(), temp.end());
        if(temp == b) {
            cout << p << endl;
            return 0;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);

/*
    VERIFICAR:
    - Corner cases
    - Estouro de variavel
    - Acesso indevido de memoria

*/

int main() {_
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> b(n);
    multiset<int> bS;
    for(int I=0; I<n; I++) {
        cin >> a[I];
    }
    for(int I=0; I<n; I++) {
        cin >> b[I];
        bS.insert(b[I]);
    }
    vector<int> candidatos;
    for(int I=0; I<n; I++) {
        candidatos.push_back((b[0]-a[I])%m);
    }
    int resp = 0x3f3f3f3f;
    for(int c : candidatos) {
        multiset<int> bSTemp = bS;
        bool erro = false;
        for(int I=0; I<n; I++) {
            int v = (a[I]+c)%m;
            if(bSTemp.find(v) == bSTemp.end()) {
                erro = true;
                break;
            }
            bSTemp.erase(bSTemp.find(v));
        }
        if(!erro) {
            resp = min(resp, c);
        }
    }
    cout << resp << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);

/*
    VERIFICAR:
    - Corner cases
    - Estouro de variavel
    - Acesso indevido de memoria

*/

int main() {_
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> b(n);
    map<int, int> freqA;
    map<int, int> freqB;
    for(int I=0; I<n; I++) {
        cin >> a[I];
        freqA[a[I]]++;
    }
    for(int I=0; I<n; I++) {
        cin >> b[I];
        freqB[b[I]]++;
    }
    int valoresUnicos = 0;
    map<int, vector<int> > freqInvertidaA;
    map<int, vector<int> > freqInvertidaB;
    for(pair<int, int> f : freqA) {
        valoresUnicos++;
        freqInvertidaA[f.second].push_back(f.first);
    }
    for(pair<int, int> f : freqB) {
        freqInvertidaB[f.second].push_back(f.first);
    }
    map<int, set<int> > relacao;
    for(pair<int, vector<int> > fA : freqInvertidaA) {
        for(pair<int, vector<int> > fB : freqInvertidaB) {
            if(fB.first == fA.first) {
                for(int v1 : fA.second) {
                    for(int v2 : fB.second) {
                        int precisa = v2 - v1;
                        if(precisa < 0) {
                            precisa = (m - v1)+v2;
                        }
                        relacao[precisa].insert(v2);
                    }
                }
            }
        }
    }
    int possibilidade = 0x3f3f3f3f;
    for(pair<int, set<int> > r : relacao) {
        if(r.second.size() == valoresUnicos) {
            possibilidade = min(possibilidade, r.first);
        }
    }
    cout << possibilidade << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);

/*
    VERIFICAR:
    - Corner cases
    - Estouro de variavel
    - Acesso indevido de memoria

*/

int main() {_
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> b(n);
    for(int I=0; I<n; I++) {
        cin >> a[I];
    }
    for(int I=0; I<n; I++) {
        cin >> b[I];
    }
    sort(b.begin(), b.end());
    int resp = 0x3f3f3f3f;
    for(int I=0; I<n; I++) {
        int x = (b[I]-a[0])%m;
        vector<int> temp(n);
        for(int J=0; J<n; J++) {
            temp[J] = (a[J]+x)%m;
        }
        sort(temp.begin(), temp.end());
        if(temp == b) {
            resp = min(resp, x);
        }
    }
    cout << resp << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);

/*
    VERIFICAR:
    - Corner cases
    - Estouro de variavel
    - Acesso indevido de memoria

*/

int main() {_
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> d(n);
    for(int I=0; I<n; I++) {
        cin >> a[I];
    }
    for(int I=0; I<n; I++) {
        cin >> b[I];
        d[I] = b[I];
    }
    sort(d.begin(), d.end());
    int resp = 0x3f3f3f3f;
    for(int I=0; I<n; I++) {
        int x = (b[I]-a[0])%m;
        vector<int> temp(n);
        for(int J=0; J<n; J++) {
            temp[J] = (a[J]+x)%m;
        }
        sort(temp.begin(), temp.end());
        if(temp == d) {
            resp = min(resp, x);
        }
    }
    cout << resp << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);

/*
    VERIFICAR:
    - Corner cases
    - Estouro de variavel
    - Acesso indevido de memoria

*/

int main() {_
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> b(n);
    multiset<int> bS;
    for(int I=0; I<n; I++) {
        cin >> a[I];
    }
    for(int I=0; I<n; I++) {
        cin >> b[I];
        bS.insert(b[I]);
    }
    vector<int> candidatos;
    for(int I=0; I<n; I++) {
        candidatos.push_back((b[I]-a[0])%m);
    }
    int resp = 0x3f3f3f3f;
    for(int c : candidatos) {
        multiset<int> bSTemp = bS;
        bool erro = false;
        for(int I=0; I<n; I++) {
            int v = (a[I]+c)%m;
            if(bSTemp.find(v) == bSTemp.end()) {
                erro = true;
                break;
            }
            bSTemp.erase(bSTemp.find(v));
        }
        if(!erro) {
            resp = min(resp, c);
        }
    }
    cout << resp << endl;
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int a[2001],b[2001];
int n,m;
int  Judge(int x)
{
    int summ=0;
    for(int i=1;i<=n;i++)
    {
        int t=a[i]+x;
        t%=m;
        summ+=t;
    }
    return summ;
}
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        cin>>b[i];
    int minn=0,maxx=0;
    for(int i=1;i<=n;i++)
        minn+=a[i];
    for(int i=1;i<=n;i++)
        maxx+=b[i];
        bool flag=0;
    if(minn>maxx){
            flag=true;
        swap(minn,maxx);
        for(int i=1;i<=n;i++)
            swap(a[i],b[i]);
    }
    int l=0,r=m-1,ans=0;
    while(r>=l)
    {
        int now=(l+r)/2;
        if(Judge(now)>=maxx)
        {
            r=now-1;
            ans=now;
        }
        else
            l=now+1;
    }
    if(flag)
        ans=m-ans;
    cout<<ans<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
long long  a[2001],b[2001];
long long  n,m;
long long   Judge(long long  x)
{
    long long  summ=0;
    for(int i=1;i<=n;i++)
    {
        int t=a[i]+x;
        t%=m;
        summ+=t;
    }
    return summ;
}
vector<int>v,s;
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        v.push_back(m-a[i]);
    }
    v.push_back(0);
    for(int i=1;i<=n;i++)
        cin>>b[i];
    long long  minn=0,maxx=0;
    for(int i=1;i<=n;i++)
        minn+=a[i];
    for(int i=1;i<=n;i++)
        maxx+=b[i];
        bool flag=0;
    sort(v.begin(),v.end());
    long long  ans=INT_MAX;
    for(int i=0;i<m;i++)
    {
        if(Judge(i)==maxx){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
long long  a[2001],b[2001];
int n,m;
long long   Judge(long long  x)
{
    long long  summ=0;
    for(int i=1;i<=n;i++)
    {
        int t=a[i]+x;
        t%=m;
        summ+=t;
    }
    return summ;
}
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        cin>>b[i];
    long long  minn=0,maxx=0;
    for(int i=1;i<=n;i++)
        minn+=a[i];
    for(int i=1;i<=n;i++)
        maxx+=b[i];
        bool flag=0;
    if(minn>maxx){
            flag=true;
        swap(minn,maxx);
        for(int i=1;i<=n;i++)
            swap(a[i],b[i]);
    }
    long long  l=0,r=m-1,ans=0;
    while(r>=l)
    {
        long long  now=(l+r)/2;
        if(Judge(now)>=maxx)
        {
            r=now-1;
            ans=now;
        }
        else
            l=now+1;
    }
    if(flag)
        ans=m-ans;
    cout<<ans<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
int a[2001],b[2001];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        cin>>b[i];
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    int all=0;
    for(int i=1;i<=n;i++)
        all+=b[i]-a[i];
    cout<<(all+m)%m<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
long long  a[2001],b[2001];
int n,m;
long long   Judge(long long  x)
{
    long long  summ=0;
    for(int i=1;i<=n;i++)
    {
        int t=a[i]+x;
        summ+=t;
    }
    return summ;
}
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        cin>>b[i];
    long long  minn=0,maxx=0;
    for(int i=1;i<=n;i++)
        minn+=a[i];
    for(int i=1;i<=n;i++)
        maxx+=b[i];
        bool flag=0;
    if(minn>maxx){
            flag=true;
        swap(minn,maxx);
        for(int i=1;i<=n;i++)
            swap(a[i],b[i]);
    }
    long long  l=0,r=m-1,ans=0;
    while(r>=l)
    {
        long long  now=(l+r)/2;
        if(Judge(now)>=maxx)
        {
            r=now-1;
            ans=now;
        }
        else
            l=now+1;
    }
    ans%=m;
    if(flag)
        ans=m-ans;
    cout<<ans<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
long long  a[2001],b[2001];
long long  n,m;
long long   Judge(long long  x)
{
    long long  summ=0;
    for(int i=1;i<=n;i++)
    {
        int t=a[i]+x;
        t%=m;
        summ+=t;
    }
    return summ;
}
vector<int>v,s;
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        v.push_back(m-a[i]);
    }
    v.push_back(0);
    for(int i=1;i<=n;i++)
        cin>>b[i];
    long long  minn=0,maxx=0;
    for(int i=1;i<=n;i++)
        minn+=a[i];
    for(int i=1;i<=n;i++)
        maxx+=b[i];
        bool flag=0;
    sort(v.begin(),v.end());
    long long  ans=INT_MAX;
    for(int i=0;i<v.size();i++)
    {
        int t=v[i];
        int neww=Judge(t);
        if((maxx-neww)%n!=0||neww<maxx)
            continue;
        if(Judge(t+(maxx-neww)/n)==maxx){
            long long  nowww=(maxx-neww)/n;
            ans=min(t+nowww,ans);
        }
    }
    ans+=m;
    ans%=m;
    cout<<ans<<endl;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int a[2001],b[2001];
vector<int>v;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        cin>>b[i];
    sort(b+1,b+n+1);
    for(int i=1;i<=n;i++)
        v.push_back((b[i]-a[1]+m)%m);
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    for(int i=0;i<v.size();i++)
    {
        bool ok=true;
        int t=v[i];
        int c[2001];
        for(int j=1;j<=n;j++)
            c[j]=(a[j]+t)%m;
        sort(c+1,c+n+1);
        for(int j=1;j<=n;j++)
            if(c[j]!=b[j])
                ok=false;
        if(ok)
        {
            cout<<t<<endl;
            return 0;
        }
    }
}


#include<iostream>
#include<algorithm>
using namespace std;
long long  a[2001],b[2001];
long long  n,m;
long long   Judge(long long  x)
{
    long long  summ=0;
    for(int i=1;i<=n;i++)
    {
        int t=a[i]+x;
        t%=m;
        summ+=t;
    }
    return summ;
}
vector<int>v,s;
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        v.push_back(m-a[i]);
    }
    v.push_back(0);
    for(int i=1;i<=n;i++)
        cin>>b[i];
    long long  minn=0,maxx=0;
    for(int i=1;i<=n;i++)
        minn+=a[i];
    for(int i=1;i<=n;i++)
        maxx+=b[i];
        bool flag=0;
    sort(v.begin(),v.end());
    long long  ans=INT_MAX;
    for(int i=0;i<v.size();i++)
    {
        int t=v[i];
        int neww=Judge(t);
        if((maxx-neww)%n!=0||neww<maxx)
            continue;
        if(Judge(t+(maxx-neww)/n)==maxx){
            long long  nowww=(maxx-neww)/n;
            ans=min(t+nowww,ans);
        }
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
long long  a[2001],b[2001];
int n,m;
long long   Judge(long long  x)
{
    long long  summ=0;
    for(int i=1;i<=n;i++)
    {
        int t=a[i]+x;
        summ+=t;
    }
    return summ;
}
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        cin>>b[i];
    long long  minn=0,maxx=0;
    for(int i=1;i<=n;i++)
        minn+=a[i];
    for(int i=1;i<=n;i++)
        maxx+=b[i];
        bool flag=0;
    if(minn>maxx){
            flag=true;
        swap(minn,maxx);
        for(int i=1;i<=n;i++)
            swap(a[i],b[i]);
    }
    long long  l=0,r=maxx,ans=0;
    while(r>=l)
    {
        long long  now=(l+r)/2;
        if(Judge(now)>=maxx)
        {
            r=now-1;
            ans=now;
        }
        else
            l=now+1;
    }
    ans%=m;
    if(flag)
        ans=m-ans;
    cout<<ans<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
long long  a[2001],b[2001];
long long  n,m;
long long   Judge(long long  x)
{
    long long  summ=0;
    for(int i=1;i<=n;i++)
    {
        int t=a[i]+x;
        t%=m;
        summ+=t;
    }
    return summ;
}
vector<int>v,s;
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        v.push_back(m-a[i]);
    }
    v.push_back(0);
    for(int i=1;i<=n;i++)
        cin>>b[i];
    long long  minn=0,maxx=0;
    for(int i=1;i<=n;i++)
        minn+=a[i];
    for(int i=1;i<=n;i++)
        maxx+=b[i];
        bool flag=0;
    sort(v.begin(),v.end());
    long long  ans=INT_MAX;
    for(int i=0;i<v.size();i++)
    {
        int t=v[i];
        int neww=Judge(t);
        if((maxx-neww)%n!=0)
            continue;
        if(Judge(t+(maxx-neww)/n)==maxx){
            long long  nowww=(maxx-neww)/n;
        nowww+=m;
        nowww%=m;
            ans=min(t+nowww,ans);
        }
    }
    ans+=m;
    ans%=m;
    cout<<ans<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
long long  a[2001],b[2001];
long long  n,m;
long long   Judge(long long  x)
{
    long long  summ=0;
    for(int i=1;i<=n;i++)
    {
        int t=a[i]+x;
        t%=m;
        summ+=t;
    }
    return summ;
}
vector<int>v,s;
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        v.push_back(m-a[i]);
    }
    v.push_back(0);
    for(int i=1;i<=n;i++)
        cin>>b[i];
    long long  minn=0,maxx=0;
    for(int i=1;i<=n;i++)
        minn+=a[i];
    for(int i=1;i<=n;i++)
        maxx+=b[i];
        bool flag=0;
    sort(v.begin(),v.end());
    long long  ans=INT_MAX;
    for(int i=0;i<m;i++)
    {
        if(Judge(i)==maxx){
            ans=i;
        }
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
int a[2001],b[2001];
int n,m;
int  Judge(int x)
{
    int summ=0;
    for(int i=1;i<=n;i++)
    {
        int t=a[i]+x;
        t%=m;
        summ+=t;
    }
    return summ;
}
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        cin>>b[i];
    int minn=0,maxx=0;
    for(int i=1;i<=n;i++)
        minn+=a[i];
    for(int i=1;i<=n;i++)
        maxx+=b[i];
    if(minn>maxx){
        swap(minn,maxx);
        for(int i=1;i<=n;i++)
            swap(a[i],b[i]);
    }
    int l=0,r=m-1,ans=0;
    while(r>=l)
    {
        int now=(l+r)/2;
        if(Judge(now)>=maxx)
        {
            r=now-1;
            ans=now;
        }
        else
            l=now+1;
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
long long  a[2001],b[2001];
long long  n,m;
long long   Judge(long long  x)
{
    if(x<0)
        return -1;
    long long  summ=0;
    for(int i=1;i<=n;i++)
    {
        int t=a[i]+x;
        t%=m;
        summ+=t;
    }
    return summ;
}
vector<int>v,s;
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        v.push_back(m-a[i]);
    }
    v.push_back(0);
    for(int i=1;i<=n;i++)
        cin>>b[i];
    long long  minn=0,maxx=0;
    for(int i=1;i<=n;i++)
        minn+=a[i];
    for(int i=1;i<=n;i++)
        maxx+=b[i];
        bool flag=0;
    sort(v.begin(),v.end());
    long long  ans=INT_MAX;
    for(int i=0;i<v.size();i++)
    {
        int t=v[i];
        int neww=Judge(t);
        if((maxx-neww)%n!=0)
            continue;
        if(Judge(t+(maxx-neww)/n)==maxx){
            long long  nowww=(maxx-neww)/n;
            ans=min(t+nowww,ans);
        }
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
long long  a[2001],b[2001];
long long  n,m;
long long   Judge(long long  x)
{
    long long  summ=0;
    for(int i=1;i<=n;i++)
    {
        int t=a[i]+x;
        t%=m;
        summ+=t;
    }
    return summ;
}
vector<int>v,s;
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        v.push_back(m-a[i]);
    }
    v.push_back(0);
    for(int i=1;i<=n;i++)
        cin>>b[i];
    long long  minn=0,maxx=0;
    for(int i=1;i<=n;i++)
        minn+=a[i];
    for(int i=1;i<=n;i++)
        maxx+=b[i];
        bool flag=0;
    sort(v.begin(),v.end());
    long long  ans=INT_MAX;
    for(int i=0;i<v.size();i++)
    {
        int t=v[i];
        int neww=Judge(t);
        if((maxx-neww)%n!=0||neww>maxx)
            continue;
        if(Judge(t+(maxx-neww)/n)==maxx){
            long long  nowww=(maxx-neww)/n;
            ans=min(t+nowww,ans);
        }
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
long long  a[2001],b[2001];
long long  n,m;
long long   Judge(long long  x)
{
    if(x<0)
        return -1;
    long long  summ=0;
    for(int i=1;i<=n;i++)
    {
        int t=a[i]+x;
        t%=m;
        summ+=t;
    }
    return summ;
}
vector<int>v,s;
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        v.push_back(m-a[i]);
    }
    v.push_back(0);
    for(int i=1;i<=n;i++)
        cin>>b[i];
    long long  minn=0,maxx=0;
    for(int i=1;i<=n;i++)
        minn+=a[i];
    for(int i=1;i<=n;i++)
        maxx+=b[i];
        bool flag=0;
    sort(v.begin(),v.end());
    long long  ans=1e18;
    for(int i=0;i<v.size();i++)
    {
        int t=v[i];
        int neww=Judge(t);
        if((maxx-neww)%n!=0)
            continue;
        if(Judge(t+(maxx-neww)/n)==maxx){
            long long  nowww=(maxx-neww)/n;
            ans=min(t+nowww,ans);
        }
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

#define ll long long
#define f(i,k,n) for(i=k;i<n;i++)
#define mi map<ll,ll>::iterator

using namespace std;

int main(){
    ll n,m,i,j;
    cin>>n>>m;
    ll a[n],b[n];
    f(i,0,n){
        cin>>a[i];
    }

    f(i,0,n){
        cin>>b[i];
    }

    map<ll,ll> m1;

    map<ll,ll> m2;

    f(i,0,n){
        mi it = m1.find(a[i]);
        if(it == m1.end()){
            m1[a[i]]=1;
        }
        else{
            it->second++;
        }
    }
    f(i,0,n){
        mi it = m2.find(b[i]);
        if(it == m2.end()){
            m2[b[i]]=1;
        }
        else{
            it->second++;
        }
    }

    mi itr = m1.begin();
    ll x=0,index=itr->first;

    //cout<<itr->second<<endl;
    for(mi it = m2.begin();it!=m2.end();it++){
            //cout<<it1->first<<ends<<it2->first<<ends<<it1->second<<ends<<it2->second<<endl;
            if((it->second == itr->second)){
                index=it->first;
                break;
            }

    }

    cout<<(m+(index-itr->first))%m<<endl;
    return 0;

}
    //cout<<index1<<ends<<index2<<endl;

    //
//    while(1){
//
//        map<ll,ll> hash;
//
//        for(mi it = m1.begin();it!=m1.end();it++){
//            hash[((it->first)+x)%m]=it->second;
//        }
//
//        int flag=0;
//        for(mi it1 = hash.begin(),it2 = m2.begin();it1!=hash.end(),it2!=m2.end();it1++,it2++){
//
//            if(it1->first != it2->first || it1->second != it2->second){
//                flag=1;
//                break;
//            }
//
//        }
//        if(flag==0)
//            break;
//        x++;
//    }


#include <bits/stdc++.h>

#define ll long long
#define f(i,k,n) for(i=k;i<n;i++)
#define mi map<ll,ll>::iterator

using namespace std;

int main(){
    ll n,m,i,j;
    cin>>n>>m;
    ll a[n],b[n];
    f(i,0,n){
        cin>>a[i];
    }

    f(i,0,n){
        cin>>b[i];
    }

    map<ll,ll> m1;

    map<ll,ll> m2;

    f(i,0,n){
        mi it = m1.find(a[i]);
        if(it == m1.end()){
            m1[a[i]]=1;
        }
        else{
            it->second++;
        }
    }
    f(i,0,n){
        mi it = m2.find(b[i]);
        if(it == m2.end()){
            m2[b[i]]=1;
        }
        else{
            it->second++;
        }
    }

    ll x=0;

    while(1){

        map<ll,ll> hash;

        for(mi it = m1.begin();it!=m1.end();it++){
            hash[((it->first)+x)%m]=it->second;
        }

        int flag=0;
        for(mi it1 = hash.begin(),it2 = m2.begin();it1!=hash.end(),it2!=m2.end();it1++,it2++){

            if(it1->first != it2->first || it1->second != it2->second){
                flag=1;
                break;
            }

        }
        if(flag==0)
            break;
        x++;
    }

    cout<<x<<endl;
    return 0;

}


#include <bits/stdc++.h>

#define ll long long
#define f(i,k,n) for(i=k;i<n;i++)
#define mi map<ll,ll>::iterator

using namespace std;

int main(){
    ll n,m,i,j;
    cin>>n>>m;
    ll a[n],b[n];
    f(i,0,n){
        cin>>a[i];
    }

    f(i,0,n){
        cin>>b[i];
    }

    map<ll,ll> m1;

    map<ll,ll> m2;

    f(i,0,n){
        mi it = m1.find(a[i]);
        if(it == m1.end()){
            m1[a[i]]=1;
        }
        else{
            it->second++;
        }
    }
    f(i,0,n){
        mi it = m2.find(b[i]);
        if(it == m2.end()){
            m2[b[i]]=1;
        }
        else{
            it->second++;
        }
    }

    ll x=0,index=0;
    mi itr = m1.begin();
    //cout<<itr->second<<endl;
    for(mi it = m2.begin();it!=m2.end();it++){
            //cout<<it1->first<<ends<<it2->first<<ends<<it1->second<<ends<<it2->second<<endl;
            if((it->second == itr->second)){
                index=it->first;
                break;
            }

    }
    //cout<<index1<<ends<<index2<<endl;
    while(index!=(itr->first+x)%m)
        x++;
    //
//    while(1){
//
//        map<ll,ll> hash;
//
//        for(mi it = m1.begin();it!=m1.end();it++){
//            hash[((it->first)+x)%m]=it->second;
//        }
//
//        int flag=0;
//        for(mi it1 = hash.begin(),it2 = m2.begin();it1!=hash.end(),it2!=m2.end();it1++,it2++){
//
//            if(it1->first != it2->first || it1->second != it2->second){
//                flag=1;
//                break;
//            }
//
//        }
//        if(flag==0)
//            break;
//        x++;
//    }

    cout<<x<<endl;
    return 0;

}