#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int msc = 200020 ;

bool b[msc] ;
int n , m , a[msc] , S[msc] ;
int l[msc] , r[msc] , len[msc] , f[msc] , g[msc] , val[msc] ;
int bel[msc] , top[msc] , net[msc] , nxt[msc] ;

void init(){
  int x ;
  for(int i = 1 ; i <= n ; i ++ ) scanf("%d",&x) , b[x] = 1 ;
  for(int i = 1 ; i <= m ; i ++ ) scanf("%d",&x) , a[i] = x , S[x] = 1 ;

  sort(a + 1 , a + m + 1) ;
  for(int i = 1 ; i <= msc - 10 ; i ++ ){
    S[i] += S[i - 1] ;
    if(S[i] != S[i - 1]) top[S[i]] = i ;
  }

  int nt = 0 ;
  for(int i = 1 ; i <= msc ; i ++ )if(b[i]){
    int j = i ;
    while(b[i + 1]) i ++ ;
    ++ nt , l[nt] = j , r[nt] = i ;
    val[nt] = S[i] - S[j - 1] ;
    len[nt] = i - j + 1 ;
        bel[nt] = S[i] ;
  }

  n = nt ;

  memset(net , 1 , sizeof(net)) ;
  for(int i = 1 ; i <= n ; i ++ ) len[i] += len[i - 1] , nxt[len[i]] = net[len[i]] = i ;
  for(int i = 1 ; i <= msc - 10 ; i ++ ) nxt[i] = max(nxt[i] , nxt[i - 1]) ;
  for(int i = msc - 10 ; i ; i -- ) net[i] = min(net[i] , net[i + 1]) ;
}

void upd(int & x , int y) { if(y > x) x = y ; }

int main(){

  cin >> n >> m ;

  init() ;

  if(n <= 20000){

    f[1] = g[1] = val[1] ; f[0] = g[0] = 0 ;
  for(int i = 2 ; i <= n ; i ++ ){
    for(int j = 0 ; j < i ; j ++ )
        upd(f[i] , g[j] + S[r[i]] - S[r[i] - (len[i] - len[j])]) ;
    for(int j = 1 ; j <= i ; j ++ )
        upd(g[i] , f[j] + S[r[j] + len[i] - len[j]] - S[r[j]]) ;
  }
    cout << max(f[n] , g[n]) << endl ;
    return 0 ;
  }
  f[0] = g[0] = 0 ;
  for(int i = 1 ; i <= n ; i ++ ){

    f[i] = f[i - 1] + val[i] ;
    for(int j = 0 ; j < bel[i] ; j ++ ){
      int Rs = top[j + 1] - 1 + len[i] - r[i] ;
      if(Rs < 0) continue ;
      int t = nxt[Rs] ;
      upd(f[i] , g[t] + S[r[i]] - S[r[i] - (len[i] - len[t])]) ;
    }

    for(int j = bel[i] ; j <= m ; j ++ ){
      int Rs = top[j] - r[i] + len[i] ;
      if(Rs < 0) continue ;
      int t = net[Rs] ;
      if(t > msc) continue ;
      upd(g[t] , f[i] + S[r[i] + len[t] - len[i]] - S[r[i]]) ;
    }

  }

  cout << max(g[n] , f[n]) << endl ;

  return 0 ;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int msc = 200020 ;

bool b[msc] ;
int n , m , a[msc] , S[msc] ;
int l[msc] , r[msc] , len[msc] , f[msc] , g[msc] , val[msc] ;
int bel[msc] , top[msc] , net[msc] , nxt[msc] ;

void init(){
  int x ;
  for(int i = 1 ; i <= n ; i ++ ) scanf("%d",&x) , b[x] = 1 ;
  for(int i = 1 ; i <= m ; i ++ ) scanf("%d",&x) , a[i] = x , S[x] = 1 ;

  sort(a + 1 , a + m + 1) ;
  for(int i = 1 ; i <= msc - 10 ; i ++ ){
    S[i] += S[i - 1] ;
    if(S[i] != S[i - 1]) top[S[i]] = i ;
  }

  int nt = 0 ;
  for(int i = 1 ; i <= msc ; i ++ )if(b[i]){
    int j = i ;
    while(b[i + 1]) i ++ ;
    ++ nt , l[nt] = j , r[nt] = i ;
    val[nt] = S[i] - S[j - 1] ;
    len[nt] = i - j + 1 ;
        bel[nt] = S[i] ;
  }

  n = nt ;

  memset(net , 1 , sizeof(net)) ;
  for(int i = 1 ; i <= n ; i ++ ) len[i] += len[i - 1] , nxt[len[i]] = net[len[i]] = i ;
  for(int i = 1 ; i <= msc - 10 ; i ++ ) nxt[i] = max(nxt[i] , nxt[i - 1]) ;
  for(int i = msc - 10 ; i ; i -- ) net[i] = min(net[i] , net[i + 1]) ;
}

void upd(int & x , int y) { if(y > x) x = y ; }

int main(){

  cin >> n >> m ;

  init() ;
  /*
  if(n <= 20000){

    f[1] = g[1] = val[1] ; f[0] = g[0] = 0 ;
  for(int i = 2 ; i <= n ; i ++ ){
    for(int j = 0 ; j < i ; j ++ )
        upd(f[i] , g[j] + S[r[i]] - S[r[i] - (len[i] - len[j])]) ;
    for(int j = 1 ; j <= i ; j ++ )
        upd(g[i] , f[j] + S[r[j] + len[i] - len[j]] - S[r[j]]) ;
  }
    cout << max(f[n] , g[n]) << endl ;
    return 0 ;
  }
  */

  f[0] = g[0] = 0 ;
  for(int i = 1 ; i <= n ; i ++ ){

    f[i] = f[i - 1] + val[i] ;
    for(int j = 0 ; j < bel[i] ; j ++ ){
      int Rs = top[j + 1] - 1 + len[i] - r[i] ;
      if(Rs < 0) continue ;
      int t = nxt[Rs] ;
      upd(f[i] , g[t] + S[r[i]] - S[r[i] - (len[i] - len[t])]) ;
    }

    upd(g[i] , f[i]) ;
    for(int j = bel[i] ; j <= m ; j ++ ){
      int Rs = top[j] - r[i] + len[i] ;
      if(Rs < 0) continue ;
      int t = net[Rs] ;
      if(t > msc) continue ;
      upd(g[t] , f[i] + S[r[i] + len[t] - len[i]] - S[r[i]]) ;
    }

  }

  cout << max(g[n] , f[n]) << endl ;

  return 0 ;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int msc = 200020 ;

bool b[msc] ;
int n , m , a[msc] , S[msc] ;
int l[msc] , r[msc] , len[msc] , f[msc] , g[msc] , val[msc] ;
int bel[msc] , top[msc] , net[msc] , nxt[msc] ;

void init(){
  int x ;
  for(int i = 1 ; i <= n ; i ++ ) scanf("%d",&x) , b[x] = 1 ;
  for(int i = 1 ; i <= m ; i ++ ) scanf("%d",&x) , a[i] = x , S[x] = 1 ;

  sort(a + 1 , a + m + 1) ;
  for(int i = 1 ; i <= msc - 10 ; i ++ ){
    S[i] += S[i - 1] ;
    if(S[i] != S[i - 1]) top[S[i]] = i ;
  }

  int nt = 0 ;
  for(int i = 1 ; i <= msc - 10 ; i ++ )if(b[i]){
    int j = i ;
    while(b[i + 1]) i ++ ;
    ++ nt , l[nt] = j , r[nt] = i ;
    val[nt] = S[i] - S[j - 1] ;
    len[nt] = i - j + 1 ;
        bel[nt] = S[i] ;
  }

  n = nt ;

  memset(net , 1 , sizeof(net)) ;
  for(int i = 1 ; i <= n ; i ++ ) len[i] += len[i - 1] , nxt[len[i]] = net[len[i]] = i ;
  for(int i = 1 ; i <= msc - 10 ; i ++ ) nxt[i] = max(nxt[i] , nxt[i - 1]) ;
  for(int i = msc - 10 ; i ; i -- ) net[i] = min(net[i] , net[i + 1]) ;
}

void upd(int & x , int y) { if(y > x) x = y ; }

int main(){

  cin >> n >> m ;

  init() ;
  /*
  if(n <= 20000){

    f[1] = g[1] = val[1] ; f[0] = g[0] = 0 ;
  for(int i = 2 ; i <= n ; i ++ ){
    for(int j = 0 ; j < i ; j ++ )
        upd(f[i] , g[j] + S[r[i]] - S[r[i] - (len[i] - len[j])]) ;
    for(int j = 1 ; j <= i ; j ++ )
        upd(g[i] , f[j] + S[r[j] + len[i] - len[j]] - S[r[j]]) ;
  }
    cout << max(f[n] , g[n]) << endl ;
    return 0 ;
  }
  */

  f[0] = g[0] = 0 ;
  for(int i = 1 ; i <= n ; i ++ ){

    f[i] = max(g[i - 1] , f[i - 1]) + val[i] ;
    for(int j = 0 ; j < bel[i] ; j ++ ){
      int Rs = top[j + 1] - 1 + len[i] - r[i] ;
      if(Rs < 0) continue ;
      int t = nxt[Rs] ;
      upd(f[i] , g[t] + S[r[i]] - S[r[i] - (len[i] - len[t])]) ;
    }

    upd(g[i] , f[i]) ;
    for(int j = bel[i] ; j <= m ; j ++ ){
      int Rs = top[j] - r[i] + len[i] ;
      if(Rs < 0) continue ;
      int t = net[Rs] ;
      if(t > msc || t <= i ) continue ;
      upd(g[t] , f[i] + S[r[i] + len[t] - len[i]] - S[r[i]]) ;
    }

  }

  cout << max(g[n] , f[n]) << endl ;

  return 0 ;
}


/*input
5 3
5 6 1 7 2
8 1 9

*/
/*input
5 5
9 2 5 7 8
6 9 7 8 3
*/
/*input
3 2
1 3 5
2 4
*/

/*input
7 6
2 4 1 9 5 6 3
10 8 7 6 9 1
*/

#include <iostream>
#include <cstdio>
#include <vector>
#include <functional>
#include <math.h>
#include <string.h>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <stdlib.h>
#include <list>
#include <assert.h>
#include <time.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define tick {cout << "HERE" << endl; }
#define N 100005
#define write(x) cout << x << sp;
template<class T>
void maximize(T &x, T y) {
	if (x < y) x = y;
}
template<class T>
void minimize(T &x, T y) {
	if (x > y) x = y;
}

int n, m, t;
vector<int> a, b;
int d[N], z[N], rig[N];
int s[2 * N];
int sum(int l, int r) {
	int ret = s[r];
	if (l >= 1) ret -= s[l - 1];
	return ret;
}

void prep() {
	a.push_back(-1e9);
	b.push_back(-1e9);
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	int cur_it = 1;
	for (int i = 0; i <= 200000; i++) {
		s[i] = s[max(0, i - 1)];
		if (cur_it <= m && b[cur_it] == i ) {
			s[i]++;
			cur_it++;
		}
	}
	int top;
	for (int i = n; i > 0; i--) {
		if (i == n || a[i + 1] - 1 != a[i]) {
			top = i;
		}
		rig[i] = top;
	}
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> t, a.push_back(t);
	for (int i = 1; i <= m; i++) cin >> t, b.push_back(t);
	prep();
	for (int i = 1; i <= n; i++) {
		maximize(z[i], z[i - 1]);
		maximize(d[i], d[i - 1]);
		maximize(d[i], z[i - 1]);
		if (rig[i] != i) continue;
		for (int j = 1; j <= m; j++) {
			if (b[j] <= a[i]) {
				int num = a[i] - b[j] + 1;
				if (i - num >= 0) {
					d[i] = max(d[i], z[i - num] + sum(b[j], a[i]));
				}
			}
			if (b[j] >= a[i]) {
				int num = b[j] - a[i];
				if (num + i <= n) {
					maximize(z[rig[i + num]], d[i] + sum(a[i] + 1, b[j]));
				}
			}
		}
		maximize(z[i], d[i]);
	}
	cout << z[n] << endl;
}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn], nxfree[maxn];

void pre()
{
    cin >> n >> m;

    FOR(i,0,n)
	cin >> num[i];
    FOR(i,0,m)
	cin >> star[i];

    sort(num,num+n);
    sort(star,star+m);

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	pos[num[i]] = i;
    }

    prfree[0] = pos[0];
    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1 && pos[i] != -1)
	    prfree[i] = prfree[i-1];
	else
	    prfree[i] = pos[i];
    }

    REP(i,maxn-2,0)
    {
	if(pos[i+1] != -1 && pos[i] != -1)
	    nxfree[i] = nxfree[i+1];
	else
	    nxfree[i] = pos[i];
    }

    FOR(i,0,m)
    {
	prsum[star[i]]++;
    }

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

 /*   FOR(i,0,10)
	cout << prfree[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	if(i)
	    dp[i] = dp[i-1] + starsum(num[i],num[i]);
	FOR(j,0,m)
	{
	    if(star[j] <= num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k)
			maxeq(dp[i] ,dp2[k-1] + starsum(num[i] - (i-k), num[i]) );
		    else
			maxeq(dp[i], starsum(num[i]-(i-k), num[i]));
		}
	    }
	}

/*	//dp2 new mode :|
	maxeq(dp2[i],dp[i]);
	if(i)
	    maxeq(dp2[i], dp2[i-1]);

	FOR(j,0,m)
	{
	    if(star[j] >= num[i])
	    {
		if(n - i - 1 >= star[j] - num[i])
		{
		    int k = nxfree[num[ i + star[j] - num[i] ]];
		    if(k != -1)
			maxeq(dp2[k], dp[i] + starsum(num[i] + 1, num[i] + (k-i)));
		}
	    }
	}*/

	//dp2
	dp2[i] = dp[i];
	if(i)
	    maxeq(dp2[i], dp2[i-1]);

	if(i != n-1 && num[i+1] == num[i]+1)
	    continue;

	FOR(j,0,m)
	{
	    if(star[j] <= num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k]+1, num[k]+i-k ));
	    }
	}
    }

  /*  FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn];

void pre()
{
    cin >> n >> m;

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	cin >> num[i];
	pos[num[i]] = i;
    }

    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1)
	    prfree[i] = prfree[i-1];
    }

    FOR(i,0,m)
    {
	cin >> star[i];
	prsum[star[i]]++;
    }

    sort(num,num+n);
    sort(star,star+m);

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

  /*  FOR(i,0,10)
	cout << prsum[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k != -1)
			maxeq(dp[i] ,dp2[k] + starsum(star[j], num[i]) );
		}
	    }
	}

	//dp2
	dp2[i] = dp[i];
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k], num[k]+i-k ));
	    }
	}
    }

  /*  FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn];

void pre()
{
    cin >> n >> m;

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	cin >> num[i];
	pos[num[i]] = i;
    }

    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1)
	    prfree[i] = prfree[i-1];
    }

    FOR(i,0,m)
    {
	cin >> star[i];
	prsum[star[i]]++;
    }

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

  /*  FOR(i,0,10)
	cout << prsum[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k != -1)
			maxeq(dp[i] ,dp2[k] + starsum(star[j], num[i]) );
		}
	    }
	}

	//dp2
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k], num[k]+i-k ));
	    }
	}
    }

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn], nxfree[maxn];

void pre()
{
    cin >> n >> m;

    FOR(i,0,n)
	cin >> num[i];
    FOR(i,0,m)
	cin >> star[i];

    sort(num,num+n);
    sort(star,star+m);

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	pos[num[i]] = i;
    }

    prfree[0] = pos[0];
    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1 && pos[i] != -1)
	    prfree[i] = prfree[i-1];
	else
	    prfree[i] = pos[i];
    }

    REP(i,maxn-2,0)
    {
	if(pos[i+1] != -1 && pos[i] != -1)
	    nxfree[i] = nxfree[i+1];
	else
	    nxfree[i] = pos[i];
    }

    FOR(i,0,m)
    {
	prsum[star[i]]++;
    }

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

 /*   FOR(i,0,10)
	cout << prfree[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	if(i)
	    dp[i] = dp[i-1];
	FOR(j,0,m)
	{
	    if(star[j] <= num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k)
			maxeq(dp[i] ,dp2[k-1] + starsum(num[i] - (i-k), num[i]) );
		    else
			maxeq(dp[i], starsum(num[i]-(i-k), num[i]));
		}
	    }
	}

/*	//dp2 new mode :|
	maxeq(dp2[i],dp[i]);
	if(i)
	    maxeq(dp2[i], dp2[i-1]);

	FOR(j,0,m)
	{
	    if(star[j] >= num[i])
	    {
		if(n - i - 1 >= star[j] - num[i])
		{
		    int k = nxfree[num[ i + star[j] - num[i] ]];
		    if(k != -1)
			maxeq(dp2[k], dp[i] + starsum(num[i] + 1, num[i] + (k-i)));
		}
	    }
	}*/

	//dp2
	dp2[i] = dp[i];
	if(i)
	    maxeq(dp2[i], dp2[i-1]);

	if(i != n-1 && num[i+1] == num[i]+1)
	    continue;

	FOR(j,0,m)
	{
	    if(star[j] <= num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k]+1, num[k]+i-k ));
	    }
	}
    }

  /*  FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn];

void pre()
{
    cin >> n >> m;

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	cin >> num[i];
	pos[num[i]] = i;
    }

    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1)
	    prfree[i] = prfree[i-1];
    }

    FOR(i,0,m)
    {
	cin >> star[i];
	prsum[star[i]]++;
    }

    sort(num,num+n);
    sort(star,star+m);

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

  /*  FOR(i,0,10)
	cout << prsum[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	if(i)
	    dp[i] = dp[i-1];
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k != -1)
			maxeq(dp[i] ,dp2[k] + starsum(star[j], num[i]) );
		}
	    }
	}

	//dp2
	dp2[i] = dp[i];
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k]+1, num[k]+i-k ));
	/*	if(i == 3)
		{
		    cout << "* " <<  j << " " << k << " " << dp2[i] << endl;
		}*/
	    }
	}
    }

  /*  FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn], nxfree[maxn];

void pre()
{
    cin >> n >> m;

    FOR(i,0,n)
	cin >> num[i];
    FOR(i,0,m)
	cin >> star[i];

    sort(num,num+n);
    sort(star,star+m);

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	pos[num[i]] = i;
    }

    prfree[0] = pos[0];
    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1 && pos[i] != -1)
	    prfree[i] = prfree[i-1];
	else
	    prfree[i] = pos[i];
    }

    REP(i,maxn-2,0)
    {
	if(pos[i+1] != -1)
	    nxfree[i] = nxfree[i+1];
    }

    FOR(i,0,m)
    {
	prsum[star[i]]++;
    }

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

 /*   FOR(i,0,10)
	cout << prfree[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	if(i)
	    dp[i] = dp[i-1];
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k)
			maxeq(dp[i] ,dp2[k-1] + starsum(num[i] - (i-k), num[i]) );
		    else
			maxeq(dp[i], starsum(num[i]-(i-k), num[i]));
		}
	    }
	}

/*	//dp2 new mode :|
	maxeq(dp2[i],dp[i]);
	if(i)
	    maxeq(dp2[i], dp2[i-1]);

	if(i == 0)
	    cout << ":| " << dp2[i] << endl;

	FOR(j,0,m)
	{
	    if(star[j] >= num[i])
	    {
		if(n - i - 1 >= star[j] - num[i])
		{
		    int k = nxfree[num[ i + star[j] - num[i] ]];
		    if(k != -1)
			maxeq(dp2[k], dp[i] + starsum(num[i] + 1, num[i] + (k-i)));
		    if(i == 0)
			cout << "* " << j << " " << k << " " << dp2[k] << endl;
		}
	    }
	}*/

	//dp2
	dp2[i] = dp[i];
	if(i)
	    maxeq(dp2[i], dp2[i-1]);

	if(i != n-1 && num[i+1] == num[i]+1)
	    continue;

	FOR(j,0,m)
	{
	    if(star[j] <= num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k]+1, num[k]+i-k ));
	/*	if(i == 3)
		{
		    cout << "* " <<  j << " " << k << " " << dp2[i] << endl;
		}*/
	    }
	}
    }

  /*  FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn];

void pre()
{
    cin >> n >> m;

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	cin >> num[i];
	pos[num[i]] = i;
    }

    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1)
	    prfree[i] = prfree[i-1];
    }

    FOR(i,0,m)
    {
	cin >> star[i];
	prsum[star[i]]++;
    }

    sort(num,num+n);
    sort(star,star+m);

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

  /*  FOR(i,0,10)
	cout << prsum[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	if(i)
	    dp[i] = dp[i-1];
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k != -1)
			maxeq(dp[i] ,dp2[k] + starsum(num[i] - (i-k), num[i]) );
		}
	    }
	}

	//dp2
	dp2[i] = dp[i];
	if(i)
	    maxeq(dp2[i], dp2[i-1]);
	FOR(j,0,m)
	{
	    if(star[j] <= num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k]+1, num[k]+i-k ));
	/*	if(i == 3)
		{
		    cout << "* " <<  j << " " << k << " " << dp2[i] << endl;
		}*/
	    }
	}
    }

  /*  FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn];

void pre()
{
    cin >> n >> m;

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	cin >> num[i];
	pos[num[i]] = i;
    }

    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1)
	    prfree[i] = prfree[i-1];
    }

    FOR(i,0,m)
    {
	cin >> star[i];
	prsum[star[i]]++;
    }

    sort(num,num+n);
    sort(star,star+m);

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

  /*  FOR(i,0,10)
	cout << prsum[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	if(i)
	    dp[i] = dp[i-1];
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k != -1)
			maxeq(dp[i] ,dp2[k] + starsum(num[i] - (i-k), num[i]) );
		}
	    }
	}

	//dp2
	dp2[i] = dp[i];
	FOR(j,0,m)
	{
	    if(star[j] <= num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k]+1, num[k]+i-k ));
	/*	if(i == 3)
		{
		    cout << "* " <<  j << " " << k << " " << dp2[i] << endl;
		}*/
	    }
	}
    }

  /*  FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn];

void pre()
{
    cin >> n >> m;

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	cin >> num[i];
	pos[num[i]] = i;
    }

    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1)
	    prfree[i] = prfree[i-1];
    }

    FOR(i,0,m)
    {
	cin >> star[i];
	prsum[star[i]]++;
    }

    sort(num,num+n);
    sort(star,star+m);

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

  /*  FOR(i,0,10)
	cout << prsum[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	if(i)
	    dp[i] = dp[i-1];
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k != -1)
			maxeq(dp[i] ,dp2[k] + starsum(num[i] - (i-k), num[i]) );
		}
	    }
	}

	//dp2
	dp2[i] = dp[i];
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k]+1, num[k]+i-k ));
	/*	if(i == 3)
		{
		    cout << "* " <<  j << " " << k << " " << dp2[i] << endl;
		}*/
	    }
	}
    }

  /*  FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn], nxfree[maxn];

void pre()
{
    cin >> n >> m;

    FOR(i,0,n)
	cin >> num[i];
    FOR(i,0,m)
	cin >> star[i];

    sort(num,num+n);
    sort(star,star+m);

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	pos[num[i]] = i;
    }

    prfree[0] = pos[0];
    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1 && pos[i] != -1)
	    prfree[i] = prfree[i-1];
	else
	    prfree[i] = pos[i];
    }

    REP(i,maxn-2,0)
    {
	if(pos[i+1] != -1 && pos[i] != -1)
	    nxfree[i] = nxfree[i+1];
	else
	    nxfree[i] = pos[i];
    }

    FOR(i,0,m)
    {
	prsum[star[i]]++;
    }

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

 /*   FOR(i,0,10)
	cout << prfree[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	if(i)
	    dp[i] = dp[i-1];
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k)
			maxeq(dp[i] ,dp2[k-1] + starsum(num[i] - (i-k), num[i]) );
		    else
			maxeq(dp[i], starsum(num[i]-(i-k), num[i]));
		}
	    }
	}

	//dp2 new mode :|
	maxeq(dp2[i],dp[i]);
	if(i)
	    maxeq(dp2[i], dp2[i-1]);

	FOR(j,0,m)
	{
	    if(star[j] >= num[i])
	    {
		if(n - i - 1 >= star[j] - num[i])
		{
		    int k = nxfree[num[ i + star[j] - num[i] ]];
		    if(k != -1)
			maxeq(dp2[k], dp[i] + starsum(num[i] + 1, num[i] + (k-i)));
		}
	    }
	}

/*	//dp2
	dp2[i] = dp[i];
	if(i)
	    maxeq(dp2[i], dp2[i-1]);

	if(i != n-1 && num[i+1] == num[i]+1)
	    continue;

	FOR(j,0,m)
	{
	    if(star[j] <= num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k]+1, num[k]+i-k ));
		if(i == 3)
		{
		    cout << "* " <<  j << " " << k << " " << dp2[i] << endl;
		}
	    }
	}*/
    }

  /*  FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn], nxfree[maxn];

void pre()
{
    cin >> n >> m;

    FOR(i,0,n)
	cin >> num[i];
    FOR(i,0,m)
	cin >> star[i];

    sort(num,num+n);
    sort(star,star+m);

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	pos[num[i]] = i;
    }

    prfree[0] = pos[0];
    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1 && pos[i] != -1)
	    prfree[i] = prfree[i-1];
	else
	    prfree[i] = pos[i];
    }

    REP(i,maxn-2,0)
    {
	if(pos[i+1] != -1)
	    nxfree[i] = nxfree[i+1];
    }

    FOR(i,0,m)
    {
	prsum[star[i]]++;
    }

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

 /*   FOR(i,0,10)
	cout << prfree[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	if(i)
	    dp[i] = dp[i-1];
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k)
			maxeq(dp[i] ,dp2[k-1] + starsum(num[i] - (i-k), num[i]) );
		    else
			maxeq(dp[i], starsum(num[i]-(i-k), num[i]));
		}
	    }
	}

/*	//dp2 new mode :|
	maxeq(dp2[i],dp[i]);
	if(i)
	    maxeq(dp2[i], dp2[i-1]);

	if(i == 0)
	    cout << ":| " << dp2[i] << endl;

	FOR(j,0,m)
	{
	    if(star[j] >= num[i])
	    {
		if(n - i - 1 >= star[j] - num[i])
		{
		    int k = nxfree[num[ i + star[j] - num[i] ]];
		    if(k != -1)
			maxeq(dp2[k], dp[i] + starsum(num[i] + 1, num[i] + (k-i)));
		    if(i == 0)
			cout << "* " << j << " " << k << " " << dp2[k] << endl;
		}
	    }
	}*/

	//dp2
	dp2[i] = dp[i];
	if(i)
	    maxeq(dp2[i], dp2[i-1]);
	FOR(j,0,m)
	{
	    if(star[j] <= num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k]+1, num[k]+i-k ));
	/*	if(i == 3)
		{
		    cout << "* " <<  j << " " << k << " " << dp2[i] << endl;
		}*/
	    }
	}
    }

  /*  FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn];

void pre()
{
    cin >> n >> m;

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	cin >> num[i];
	pos[num[i]] = i;
    }

    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1)
	    prfree[i] = prfree[i-1];
    }

    FOR(i,0,m)
    {
	cin >> star[i];
	prsum[star[i]]++;
    }

    int p = 0;
    FOR(i,0,m)
    {
	while(num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

  /*  FOR(i,0,10)
	cout << prsum[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
	//dp
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k != -1)
			maxeq(dp[i] ,dp2[k] + starsum(star[j], num[i]) );
		}
	    }
	}

	//dp2
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k], num[k]+i-k ));
	    }
	}
    }

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn], nxfree[maxn];

void pre()
{
    cin >> n >> m;

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	cin >> num[i];
	pos[num[i]] = i;
    }

    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1)
	    prfree[i] = prfree[i-1];
    }

    REP(i,maxn-2,0)
    {
	if(pos[i+1] != -1)
	    nxfree[i] = nxfree[i+1];
    }

    FOR(i,0,m)
    {
	cin >> star[i];
	prsum[star[i]]++;
    }

    sort(num,num+n);
    sort(star,star+m);

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

  /*  FOR(i,0,10)
	cout << prsum[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	if(i)
	    dp[i] = dp[i-1];
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k != -1)
			maxeq(dp[i] ,dp2[k] + starsum(num[i] - (i-k), num[i]) );
		}
	    }
	}

	//dp2 new mode :|
	maxeq(dp2[i],dp[i]);
	if(i)
	    maxeq(dp2[i], dp2[i-1]);
	FOR(j,0,m)
	{
	    if(star[j] >= num[i])
	    {
		if(n - i - 1 >= star[j] - num[i])
		{
		    int k = nxfree[num[ i + star[j] - num[i] ]];
		    if(k != -1)
			maxeq(dp2[k], dp[i] + starsum(num[i] + 1, num[i] + (k-i)));
		}
	    }
	}

/*	//dp2
	dp2[i] = dp[i];
	if(i)
	    maxeq(dp2[i], dp2[i-1]);
	FOR(j,0,m)
	{
	    if(star[j] <= num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k]+1, num[k]+i-k ));
		if(i == 3)
		{
		    cout << "* " <<  j << " " << k << " " << dp2[i] << endl;
		}
	    }
	}*/
    }

  /*  FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn], nxfree[maxn];

void pre()
{
    cin >> n >> m;

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	cin >> num[i];
	pos[num[i]] = i;
    }

    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1)
	    prfree[i] = prfree[i-1];
	else
	    prfree[i] = pos[i];
    }

    REP(i,maxn-2,0)
    {
	if(pos[i+1] != -1)
	    nxfree[i] = nxfree[i+1];
    }

    FOR(i,0,m)
    {
	cin >> star[i];
	prsum[star[i]]++;
    }

    sort(num,num+n);
    sort(star,star+m);

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

  /*  FOR(i,0,10)
	cout << prsum[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	if(i)
	    dp[i] = dp[i-1];
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k != -1)
			maxeq(dp[i] ,dp2[k] + starsum(num[i] - (i-k), num[i]) );
		}
	    }
	}

/*	//dp2 new mode :|
	maxeq(dp2[i],dp[i]);
	if(i)
	    maxeq(dp2[i], dp2[i-1]);

	if(i == 0)
	    cout << ":| " << dp2[i] << endl;

	FOR(j,0,m)
	{
	    if(star[j] >= num[i])
	    {
		if(n - i - 1 >= star[j] - num[i])
		{
		    int k = nxfree[num[ i + star[j] - num[i] ]];
		    if(k != -1)
			maxeq(dp2[k], dp[i] + starsum(num[i] + 1, num[i] + (k-i)));
		    if(i == 0)
			cout << "* " << j << " " << k << " " << dp2[k] << endl;
		}
	    }
	}*/

	//dp2
	dp2[i] = dp[i];
	if(i)
	    maxeq(dp2[i], dp2[i-1]);
	FOR(j,0,m)
	{
	    if(star[j] <= num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k]+1, num[k]+i-k ));
	/*	if(i == 3)
		{
		    cout << "* " <<  j << " " << k << " " << dp2[i] << endl;
		}*/
	    }
	}
    }

/*    FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<ld,ld>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MAXINT ((~0) ^ (1 << 31))
#define MAXLL ((~0) ^ ((ll)1 << 63))
#define INF ((int)2e9)
#define INFL ((ll)9e18)
#define FOR(i,j,k) for(int i = j; i < k; i++)
#define REP(i,j,k) for(int i = j; i >= k; i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()

//srand (time(NULL));

using namespace std;

setmax(1e5+10);

int num[maxn], s[maxn], n , m;
ll sum,maxi;

int check(int l, int r)
{
    int ans =0;
    FOR(i,0,m) if(s[i] >= l && s[i] <= r) ans++;
    return ans;
}

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

    cin >> n >> m;
    FOR(i,0,n) cin >> num[i];
    FOR(i,0,m) cin >> s[i];
    sort(num,num+n);
    sort(s,s+m);
    sum = n;

    FOR(i,0,n)
    {
        sum--;
        maxi = max((int)maxi, check(num[i]-n+sum+1,num[i]+sum));
      //  if(maxi == 2) cout << "* " << n << endl;
    }
    cout << maxi;
}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn], nxfree[maxn];

void pre()
{
    cin >> n >> m;

    FOR(i,0,n)
	cin >> num[i];
    FOR(i,0,m)
	cin >> star[i];

    sort(num,num+n);
    sort(star,star+m);

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	pos[num[i]] = i;
    }

    prfree[0] = pos[0];
    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1 && pos[i] != -1)
	    prfree[i] = prfree[i-1];
	else
	    prfree[i] = pos[i];
    }

    REP(i,maxn-2,0)
    {
	if(pos[i+1] != -1 && pos[i] != -1)
	    nxfree[i] = nxfree[i+1];
	else
	    nxfree[i] = pos[i];
    }

    FOR(i,0,m)
    {
	prsum[star[i]]++;
    }

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

 /*   FOR(i,0,10)
	cout << prfree[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	if(i)
	{
	    dp[i] = dp[i-1] + starsum(num[i],num[i]);
	    maxeq(dp[i], dp2[i-1] + starsum(num[i],num[i]));
	}

	FOR(j,0,m)
	{
	    if(star[j] <= num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k)
			maxeq(dp[i] ,dp2[k-1] + starsum(num[i] - (i-k), num[i]) );
		    else
			maxeq(dp[i], starsum(num[i]-(i-k), num[i]));
		}
	    }
	}

/*	//dp2 new mode :|
	maxeq(dp2[i],dp[i]);
	if(i)
	    maxeq(dp2[i], dp2[i-1]);

	FOR(j,0,m)
	{
	    if(star[j] >= num[i])
	    {
		if(n - i - 1 >= star[j] - num[i])
		{
		    int k = nxfree[num[ i + star[j] - num[i] ]];
		    if(k != -1)
			maxeq(dp2[k], dp[i] + starsum(num[i] + 1, num[i] + (k-i)));
		}
	    }
	}*/

	//dp2
	dp2[i] = dp[i];

	if(i != n-1 && num[i+1] == num[i]+1)
	    continue;

	FOR(j,0,m)
	{
	    if(star[j] <= num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k]+1, num[k]+i-k ));
	    }
	}
    }

  /*  FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
#define FORV(i, v) FOR(i, 0, ((v).size()))
#define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()
#define autodef(x,v) typeof(v) x = (v)
#define autoref(x,v) typeof(v)& x = (v)
#define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)

//typedef complex<double> Point;
//#define X real()
//#define Y imag()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

const int INF = (int) 2e9;
const ll INFL = (ll) 9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const ll MAXLL = ((~0) ^ ((ll)1 << 63));

template<class T> inline T pow2(T a) { return a*a;}
template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}

//srand (time(NULL));

setmax(2e5+10);

int n,m, pos[maxn], star[maxn], num[maxn], prev[maxn], prsum[maxn], prfree[maxn];
int dp[maxn], dp2[maxn];

void pre()
{
    cin >> n >> m;

    fill(pos,pos+maxn,-1);
    FOR(i,0,n)
    {
	cin >> num[i];
	pos[num[i]] = i;
    }

    FOR(i,1,maxn)
    {
	if(pos[i-1] != -1)
	    prfree[i] = prfree[i-1];
    }

    FOR(i,0,m)
    {
	cin >> star[i];
	prsum[star[i]]++;
    }

    sort(num,num+n);
    sort(star,star+m);

   // cout << "input Done()" << endl;

    int p = 0;
    FOR(i,0,m)
    {
	while(p < n && num[p] <= star[i])
	    p++;
	prev[i] = p-1;
    }

    FOR(i,1,maxn)
    {
	prsum[i] += prsum[i-1];
    }
}

int starsum(int i, int j)
{
    return prsum[j] - prsum[i-1];
}

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

    pre();

   // cout << "pre Done :|" << endl;

   /* FOR(i,0,m)
	cout << prev[i] << " ";
    cout << endl;*/

  /*  FOR(i,0,10)
	cout << prsum[i] << " ";
    cout << endl;*/

    FOR(i,0,n)
    {
//	cout << i << endl;
	//dp
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		if(i >= num[i] - star[j])
		{
		    int k = prfree[num[i - (num[i] - star[j])]];
		    if(k != -1)
			maxeq(dp[i] ,dp2[k] + starsum(star[j], num[i]) );
		}
	    }
	}

	//dp2
	dp2[i] = dp[i];
	FOR(j,0,m)
	{
	    if(star[j] < num[i])
	    {
		int k = prev[j];
		if(k != -1)
		    maxeq(dp2[i], dp[k] + starsum(num[k]+1, num[k]+i-k ));
	/*	if(i == 3)
		{
		    cout << "* " <<  j << " " << k << " " << dp2[i] << endl;
		}*/
	    }
	}
    }

  /*  FOR(i,0,n)
    {
	cout << i << " : " << dp[i] << " " << dp2[i] << endl;
    }*/

    cout << dp2[n-1] << endl;

}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;

const int MAXN = 100005;
const int MAXM = 2005;

int g[MAXN], f[MAXN];
//  g[i] the maximum # of stars can be gained when monster[i] is fixed (only consider the stars on the left side of monster[i])
//  f[i] the maximum # of stars can be gained using monster[1 .. i]  (it's obvious that at least one of the monster(1..i) is fixed)

int n, m, monster[MAXN], star[MAXM], start[MAXN];

void upd(int &x, int y)  {
	if (y > x) x = y;
}

int main()  {
	    //read input
    	scanf("%d%d", &n, &m);
    	for (int i = 0; i < n; i ++)  {
    			scanf("%d", &monster[i]);
    	}
    	for (int i = 0; i < m; i ++)  {
   	 			scanf("%d", &star[i]);
    	}

    	//blocks
    	sort(monster, monster + n);
    	sort(star, star + m);
   		for (int i = 0; i < n; i ++)  {
   				if (!i || monster[i] != monster[i - 1] + 1)  {
   						start[i] = i;
   				}else  {
   						start[i] = start[i - 1];
   				}
   		}

   		//dp
   		memset(g, 0, sizeof g);
   		memset(f, 0, sizeof f);
   		for (int i = 0; i < n; i ++)  {
   				int nxtstar = upper_bound(star, star + m, monster[i]) - star;
   				//CONSIDER LHS (CALC G[I])
   				for (int leftstar = nxtstar - 1; leftstar >= 0; leftstar --)  {
   						int leftmonster = i - (monster[i] - star[leftstar]);
   						if (leftmonster < 0)  break;
   						leftmonster = start[leftmonster] - 1;
   						upd(g[i], (leftmonster >= 0 ? f[leftmonster] : 0) + nxtstar - leftstar);
   				}

   				//CONSIDER RHS (UPDATER F[J > I])
   				for (int rightstar = nxtstar; rightstar < m; rightstar ++)  {
   						int rightmonster = i + (star[rightstar] - monster[i]);
   						if (rightmonster >= n)  break;
   						upd(f[rightmonster], g[i] + rightstar - nxtstar + 1);
   				}

   				if (i > 0) upd(f[i], f[i - 1]);
   				upd(f[i], g[i]);

   		}
   		printf("%d\n", f[n - 1]);
		return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;

const int MAXN = 100005;
const int MAXM = 2005;

int g[MAXN], f[MAXN];
//  g[i] the maximum # of stars can be gained when monster[i] is fixed (only consider the stars on the left side of monster[i])
//  f[i] the maximum # of stars can be gained using monster[1 .. i]  (it's obvious that at least one of the monster(1..i) is fixed)

int n, m, monster[MAXN], star[MAXM], start[MAXN];

void upd(int &x, int y)  {
	if (y > x) x = y;
}

int main()  {
	    //read input
    	scanf("%d%d", &n, &m);
    	for (int i = 0; i < n; i ++)  {
    			scanf("%d", &monster[i]);
    	}
    	for (int i = 0; i < m; i ++)  {
   	 			scanf("%d", &star[i]);
    	}

    	//blocks
    	sort(monster, monster + n);
    	sort(star, star + m);
   		for (int i = 0; i < n; i ++)  {
   				if (!i || monster[i] != monster[i - 1] + 1)  {
   						start[i] = i;
   				}else  {
   						start[i] = start[i - 1];
   				}
   		}

   		//dp
   		memset(g, 0, sizeof g);
   		memset(f, 0, sizeof f);
   		for (int i = 0; i < n; i ++)  {
   				int nxtstar = upper_bound(star, star + m, monster[i]) - star;
   				//CONSIDER LHS (CALC G[I])
   				for (int leftstar = nxtstar - 1; leftstar >= 0; leftstar --)  {
   						int leftmonster = i - (monster[i] - star[leftstar]);
   						if (leftmonster < 0)  break;
   						leftmonster = start[leftmonster] - 1;
   						upd(g[i], leftmonster >= 0 ? f[leftmonster] + nxtstar - leftstar : 0);
   				}

   				//CONSIDER RHS (UPDATER F[J > I])
   				for (int rightstar = nxtstar; rightstar < m; rightstar ++)  {
   						int rightmonster = i + (star[rightstar] - monster[i]);
   						if (rightmonster >= n)  break;
   						upd(f[rightmonster], g[i] + rightstar - nxtstar + 1);
   				}

   				if (i > 0) upd(f[i], f[i - 1]);
   				upd(f[i], g[i]);

   		}
   		printf("%d\n", f[n - 1]);
		return 0;
}


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

using namespace std;

const long double EPS = 1e-7;
const long double INF = 1e9;

long double getIntersection(int x, int y, int vx, int vy, int dy, int lx, int rx, bool strict=true)
{
	long double t = (long double)(dy - y) / vy;
	if (t < 0)
		return -1;
	long double dx = t * vx + x;
	if (dx - lx > EPS && rx - dx > EPS)
		return t;
	else if (!strict && (dx - lx > -EPS && rx - dx > -EPS))
		return t;
	else
		return -1;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	long double mx = INF, mn = 0;
	for (int i = 0; i < n; i++)
	{
		int x, y, vx, vy;
		cin >> x >> y >> vx >> vy;
		vector<long double> v;
		if (vx != 0)
		{
			v.push_back(getIntersection(x, y, vx, vy, y1, x1, x2));
			v.push_back(getIntersection(x, y, vx, vy, y2, x1, x2));
		}
		else if (x <= x1 || x >= x2)
		{
			cout << -1 << endl;
			return 0;
		}
		if (vy != 0)
		{
			v.push_back(getIntersection(y, x, vy, vx, x1, y1, y2, false));
			v.push_back(getIntersection(y, x, vy, vx, x2, y1, y2, false));
		}
		else if (y <= y1 || y >= y2)
		{
			cout << -1 << endl;
			return 0;
		}
		if (vx == 0 && vy == 0)
			continue;
		if (x > x1 && x < x2 && y > y1 && y < y2)
			v.push_back(0);
		sort(v.begin(), v.end(), greater<long double>());
		while (!v.empty() && v.back() < 0)
			v.pop_back();
		if (v.size() == 0 || v.size() == 1)
		{
			cout << -1 << endl;
			return 0;
		}
		else if (v.size() == 2)
		{
			mx = min(mx, v[0]);
			mn = max(mn, v[1]);
		}
		else
			throw "Should not happen";

	}
	cout.precision(10);
	if (mx - mn < EPS)
		cout << -1 << endl;
	else
		cout << fixed << mn + EPS << endl;
}


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

using namespace std;

const long double EPS = 1e-6;
const long double INF = 1e9;

long double getIntersection(int x, int y, int vx, int vy, int dy, int lx, int rx, bool strict=true)
{
	long double t = (long double)(dy - y) / vy;
	if (t < 0)
		return -1;
	long double dx = t * vx + x;
	if (dx - lx > EPS && rx - dx > EPS)
		return t;
	else if (!strict && (dx - lx > -EPS && rx - dx > -EPS))
		return t;
	else
		return -1;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	long double mx = INF, mn = 0;
	for (int i = 0; i < n; i++)
	{
		int x, y, vx, vy;
		cin >> x >> y >> vx >> vy;
		vector<long double> v;
		if (vx > 0)
		{
			v.push_back(getIntersection(x, y, vx, vy, y1, x1, x2));
			v.push_back(getIntersection(x, y, vx, vy, y2, x1, x2));
		}
		else if (x <= x1 || x >= x2)
		{
			cout << -1 << endl;
			return 0;
		}
		if (vy > 0)
		{
			v.push_back(getIntersection(y, x, vy, vx, x1, y1, y2, false));
			v.push_back(getIntersection(y, x, vy, vx, x2, y1, y2, false));
		}
		else if (y <= y1 || y >= y2)
		{
			cout << -1 << endl;
			return 0;
		}
		if (vx == 0 && vy == 0)
			continue;
		if (x > x1 && x < x2 && y > y1 && y < y2)
			v.push_back(0);
		sort(v.begin(), v.end(), greater<long double>());
		while (!v.empty() && v.back() < 0)
			v.pop_back();
		if (v.size() == 0)
		{
			cout << -1 << endl;
			return 0;
		}
		else if (v.size() == 2)
		{
			mx = min(mx, v[0]);
			mn = max(mn, v[1]);
		}
		else
			throw "Should not happen";

	}
	cout.precision(10);
	if (mx - mn < -EPS)
		cout << -1 << endl;
	else
		cout << fixed << mn << endl;
}


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

using namespace std;

const long double EPS = 1e-12;
const long double INF = 1e9;

long double getIntersection(int x, int y, int vx, int vy, int dy, int lx, int rx, bool strict=true)
{
	long double t = (long double)(dy - y) / vy;
	if (t < 0)
		return -1;
	long double dx = t * vx + x;
	if (dx - lx > EPS && rx - dx > EPS)
		return t;
	else if (!strict && (dx - lx > -EPS && rx - dx > -EPS))
		return t;
	else
		return -1;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	long double mx = INF, mn = 0;
	for (int i = 0; i < n; i++)
	{
		int x, y, vx, vy;
		cin >> x >> y >> vx >> vy;
		vector<long double> v;
		if (vx != 0)
		{
			v.push_back(getIntersection(y, x, vy, vx, x1, y1, y2, false));
			v.push_back(getIntersection(y, x, vy, vx, x2, y1, y2, false));

		}
		else if (x <= x1 || x >= x2)
		{
			cout << -1 << endl;
			return 0;
		}
		if (vy != 0)
		{
			v.push_back(getIntersection(x, y, vx, vy, y1, x1, x2));
			v.push_back(getIntersection(x, y, vx, vy, y2, x1, x2));

		}
		else if (y <= y1 || y >= y2)
		{
			cout << -1 << endl;
			return 0;
		}
		if (vx == 0 && vy == 0)
			continue;
		if (x > x1 && x < x2 && y > y1 && y < y2)
			v.push_back(0);
		sort(v.begin(), v.end(), greater<long double>());
		while (!v.empty() && v.back() < 0)
			v.pop_back();
		if (v.size() == 0 || v.size() == 1)
		{
			cout << -1 << endl;
			return 0;
		}
		else if (v.size() == 2)
		{
			mx = min(mx, v[0]);
			mn = max(mn, v[1]);
		}
		else
			throw "Should not happen";

	}
	cout.precision(10);
	if (mx - mn < EPS)
		cout << -1 << endl;
	else
		cout << fixed << mn + EPS << endl;
}


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

using namespace std;

const long double EPS = 1e-7;
const long double INF = 1e9;

long double getIntersection(int x, int y, int vx, int vy, int dy, int lx, int rx, bool strict=true)
{
	long double t = (long double)(dy - y) / vy;
	if (t < 0)
		return -1;
	long double dx = t * vx + x;
	if (dx - lx > EPS && rx - dx > EPS)
		return t;
	else if (!strict && (dx - lx > -EPS && rx - dx > -EPS))
		return t;
	else
		return -1;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	long double mx = INF, mn = 0;
	for (int i = 0; i < n; i++)
	{
		int x, y, vx, vy;
		cin >> x >> y >> vx >> vy;
		vector<long double> v;
		if (vx > 0)
		{
			v.push_back(getIntersection(x, y, vx, vy, y1, x1, x2));
			v.push_back(getIntersection(x, y, vx, vy, y2, x1, x2));
		}
		else if (x <= x1 || x >= x2)
		{
			cout << -1 << endl;
			return 0;
		}
		if (vy > 0)
		{
			v.push_back(getIntersection(y, x, vy, vx, x1, y1, y2, false));
			v.push_back(getIntersection(y, x, vy, vx, x2, y1, y2, false));
		}
		else if (y <= y1 || y >= y2)
		{
			cout << -1 << endl;
			return 0;
		}
		if (vx == 0 && vy == 0)
			continue;
		if (x > x1 && x < x2 && y > y1 && y < y2)
			v.push_back(0);
		sort(v.begin(), v.end(), greater<long double>());
		while (!v.empty() && v.back() < 0)
			v.pop_back();
		if (v.size() == 0)
		{
			cout << -1 << endl;
			return 0;
		}
		else if (v.size() == 2)
		{
			mx = min(mx, v[0]);
			mn = max(mn, v[1]);
		}
		else
			throw "Should not happen";

	}
	cout.precision(10);
	if (mx - mn < EPS)
		cout << -1 << endl;
	else
		cout << fixed << mn + EPS << endl;
}


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

using namespace std;

const long double EPS = 1e-7;
const long double INF = 1e9;

long double getIntersection(int x, int y, int vx, int vy, int dy, int lx, int rx, bool strict=true)
{
	if (vy == 0)
		return -1;
	long double t = (long double)(dy - y) / vy;
	if (t < 0)
		return -1;
	long double dx = t * vx + x;
	if (dx - lx > EPS && rx - dx > EPS)
		return t;
	else if (!strict && (dx - lx > -EPS && rx - dx > -EPS))
		return t;
	else
		return -1;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	long double mx = INF, mn = 0;
	for (int i = 0; i < n; i++)
	{
		int x, y, vx, vy;
		cin >> x >> y >> vx >> vy;
		vector<long double> v;
		if (vx != 0)
		{
			v.push_back(getIntersection(x, y, vx, vy, y1, x1, x2));
			v.push_back(getIntersection(x, y, vx, vy, y2, x1, x2));
		}
		else if (x <= x1 || x >= x2)
		{
			cout << -1 << endl;
			return 0;
		}
		if (vy != 0)
		{
			v.push_back(getIntersection(y, x, vy, vx, x1, y1, y2, false));
			v.push_back(getIntersection(y, x, vy, vx, x2, y1, y2, false));
		}
		else if (y <= y1 || y >= y2)
		{
			cout << -1 << endl;
			return 0;
		}
		if (vx == 0 && vy == 0)
			continue;
		if (x > x1 && x < x2 && y > y1 && y < y2)
			v.push_back(0);
		sort(v.begin(), v.end(), greater<long double>());
		while (!v.empty() && v.back() < 0)
			v.pop_back();
		if (v.size() == 0 || v.size() == 1)
		{
			cout << -1 << endl;
			return 0;
		}
		else if (v.size() == 2)
		{
			mx = min(mx, v[0]);
			mn = max(mn, v[1]);
		}
		else
			throw "Should not happen";

	}
	cout.precision(10);
	if (mx - mn < EPS)
		cout << -1 << endl;
	else
		cout << fixed << mn + EPS << endl;
}


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

#define x first
#define y second
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn = 1000 * 100 + 5;
int n; pair<double, double> m[maxn], v[maxn]; double t[maxn][4], javab = -1, x[2], y[2];

void input()
{
	scanf("%d %lf %lf %lf %lf", &n, &x[0], &y[0], &x[1], &y[1]);
	for(int i = 0; i < n; i++)
		scanf("%lf %lf %lf %lf", &m[i].x, &m[i].y, &v[i].x, &v[i].y);
}

double fx(double x, double y0, double y1, int an)
{
	if(m[an].x >= x && v[an].x >= 0) return -1;
	if(m[an].x <= x && v[an].x <= 0) return -1;
	if(m[an].y >= max(y0, y1) && v[an].y >= 0) return -1;
	if(m[an].y <= min(y0, y1) && v[an].y <= 0) return -1;
	if(y0 > y1) swap(y0, y1);
	double a = (x - m[an].x) / v[an].x; double aa = (m[an].y + v[an].y * a);
	if(y0 <= aa && y1 >= aa) return a;
	return -1;
}

double fy(double y, double x0, double x1, int an)
{
	if(m[an].y >= y && v[an].y >= 0) return -1;
	if(m[an].y <= y && v[an].y <= 0) return -1;
	if(m[an].x >= max(x0, x1) && v[an].x >= 0) return -1;
	if(m[an].x <= min(x0, x1) && v[an].x <= 0) return -1;
	if(x0 > x1) swap(x0, x1);
	double a = (y - m[an].y) / v[an].y; double aa = (m[an].x + v[an].x * a);
	if(x0 <= aa && x1 >= aa) return a;
	return -1;
}

void solved()
{
	double minn = 0;
	for(int i = 0; i < n; i++)
	{
		t[i][0] = fx(x[0], y[0], y[1], i); t[i][1] = fx(x[1], y[0], y[1], i);
		t[i][2] = fy(y[0], x[0], x[1], i); t[i][3] = fy(y[1], x[0], x[1], i);
		sort(t[i], t[i] + 4);
		if(m[i].x >= min(x[0], x[1]) && m[i].x <= max(x[0], x[1]) && m[i].y >= min(y[0], y[1]) && m[i].y <= max(y[0], y[1]))
			t[i][2] = 0;
if(m[i].x>min(x[0], x[1]) && m[i].x < max(x[0], x[1]) && m[i].y > min(y[0], y[1]) && m[i].y < max(y[0], y[1]) && v[i].x == 0 && v[i].y == 0)
	{
		t[i][0] = 0; t[i][1] = 0; t[i][2] = 0; t[i][3] = 1;
	}
		if(t[i][1] > -1) swap(t[i][1], t[i][2]);
		if(t[i][3] == -1 || t[i][2] == -1 || t[i][2] == t[i][3]) return;
		minn = max((double) t[i][2], (double) minn);
	}
	for(int i = 0; i < n; i++)
		if((double) t[i][3] < (double) minn)
			return;
	javab = minn;
}

void output()
{
	if(javab == -1) cout << javab << endl;
	else cout << fixed << setprecision(6) << javab << endl;
}

int main()
{
	input();
	solved();
	output();
	return 0;
}


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

#define x first
#define y second
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn = 1000 * 100 + 5;
int n; pair<double, double> m[maxn], v[maxn]; double t[maxn][4], javab = -1, x[2], y[2];

void input()
{
	scanf("%d %lf %lf %lf %lf", &n, &x[0], &y[0], &x[1], &y[1]);
	for(int i = 0; i < n; i++)
		scanf("%lf %lf %lf %lf", &m[i].x, &m[i].y, &v[i].x, &v[i].y);
}

double fx(double x, double y0, double y1, int an)
{
	if(m[an].x >= x && v[an].x >= 0) return -1;
	if(m[an].x <= x && v[an].x <= 0) return -1;
	if(m[an].y >= max(y0, y1) && v[an].y >= 0) return -1;
	if(m[an].y <= min(y0, y1) && v[an].y <= 0) return -1;
	if(y0 > y1) swap(y0, y1);
	double a = (x - m[an].x) / v[an].x; double aa = (m[an].y + v[an].y * a);
	if(y0 <= aa && y1 >= aa) return a;
	return -1;
}

double fy(double y, double x0, double x1, int an)
{
	if(m[an].y >= y && v[an].y >= 0) return -1;
	if(m[an].y <= y && v[an].y <= 0) return -1;
	if(m[an].x >= max(x0, x1) && v[an].x >= 0) return -1;
	if(m[an].x <= min(x0, x1) && v[an].x <= 0) return -1;
	if(x0 > x1) swap(x0, x1);
	double a = (y - m[an].y) / v[an].y; double aa = (m[an].x + v[an].x * a);
	if(x0 <= aa && x1 >= aa) return a;
	return -1;
}

void solved()
{
	double minn = 0;
	for(int i = 0; i < n; i++)
	{
		t[i][0] = fx(x[0], y[0], y[1], i); t[i][1] = fx(x[1], y[0], y[1], i);
		t[i][2] = fy(y[0], x[0], x[1], i); t[i][3] = fy(y[1], x[0], x[1], i);
		sort(t[i], t[i] + 4);
		if(m[i].x >= min(x[0], x[1]) && m[i].x <= max(x[0], x[1]) && m[i].y >= min(y[0], y[1]) && m[i].y <= max(y[0], y[1]))
			t[i][2] = 0;
		if(t[i][3] == -1 || t[i][2] == -1) return;
		if(t[i][1] > -1) swap(t[i][1], t[i][2]);
		minn = max((double) t[i][2], (double) minn);
	}
	for(int i = 0; i < n; i++)
		if((double) t[i][3] < (double) minn)
			return;
	javab = minn;
}

void output()
{
	if(javab == -1) cout << javab << endl;
	else cout << fixed << setprecision(6) << javab << endl;
}

int main()
{
	input();
	solved();
	output();
	return 0;
}


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

#define x first
#define y second
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn = 1000 * 100 + 5;
int n; pair<double, double> m[maxn], v[maxn]; double t[maxn][4], javab = -1, x[2], y[2];

void input()
{
	scanf("%d %lf %lf %lf %lf", &n, &x[0], &y[0], &x[1], &y[1]);
	for(int i = 0; i < n; i++)
		scanf("%lf %lf %lf %lf", &m[i].x, &m[i].y, &v[i].x, &v[i].y);
}

double fx(double x, double y0, double y1, int an)
{
	if(m[an].x >= x && v[an].x >= 0) return -1;
	if(m[an].x <= x && v[an].x <= 0) return -1;
	if(y0 > y1) swap(y0, y1);
	double a = (x - m[an].x) / v[an].x; double aa = (m[an].y + v[an].y * a);
	if(y0 <= aa && y1 >= aa) return a;
	return -1;
}

double fy(double y, double x0, double x1, int an)
{
	if(m[an].y >= y && v[an].y >= 0) return -1;
	if(m[an].y <= y && v[an].y <= 0) return -1;
	if(x0 > x1) swap(x0, x1);
	double a = (y - m[an].y) / v[an].y; double aa = (m[an].x + v[an].x * a);
	if(x0 <= aa && x1 >= aa) return a;
	return -1;
}

void solved()
{
	double minn = 0;
	for(int i = 0; i < n; i++)
	{
		t[i][0] = fx(x[0], y[0], y[1], i); t[i][1] = fx(x[1], y[0], y[1], i);
		t[i][2] = fy(y[0], x[0], x[1], i); t[i][3] = fy(y[1], x[0], x[1], i);
		sort(t[i], t[i] + 4);
		if(m[i].x > min(x[0], x[1]) && m[i].x < max(x[0], x[1]) && m[i].y > min(y[0], y[1]) && m[i].y < max(y[0], y[1]))
			t[i][2] = 0;
		if(t[i][3] == -1 || t[i][2] == -1) return;
		if(t[i][1] > -1) swap(t[i][1], t[i][2]);
		minn = max((double) t[i][2], (double) minn);
	}
	for(int i = 0; i < n; i++)
		if((double) t[i][3] < (double) minn)
			return;
	javab = minn;
}

void output()
{
	if(javab == -1) cout << javab << endl;
	else cout << fixed << setprecision(6) << javab << endl;
}

int main()
{
	input();
	solved();
	output();
	return 0;
}


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

#define x first
#define y second
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn = 1000 * 100 + 5;
int n; pair<double, double> m[maxn], v[maxn]; double t[maxn][4], javab = -1, x[2], y[2];

void input()
{
	cin >> n >> x[0] >> y[0] >> x[1] >> y[1];
	for(int i = 0; i < n; i++)
		cin >> m[i].x >> m[i].y >> v[i].x >> v[i].y;
}

double fx(double x, double y0, double y1, int an)
{
	if(m[an].x >= x && v[an].x >= 0) return -1;
	if(m[an].x <= x && v[an].x <= 0) return -1;
	if(y0 > y1) swap(y0, y1);
	double a = (x - m[an].x) / v[an].x; double aa = (m[an].y + v[an].y * a);
	if(y0 <= aa && y1 >= aa) return a;
	return -1;
}

double fy(double y, double x0, double x1, int an)
{
	if(m[an].y >= y && v[an].y >= 0) return -1;
	if(m[an].y <= y && v[an].y <= 0) return -1;
	if(x0 > x1) swap(x0, x1);
	double a = (y - m[an].y) / v[an].y; double aa = (m[an].x + v[an].x * a);
	if(x0 <= aa && x1 >= aa) return a;
	return -1;
}

void solved()
{
	double minn = 0;
	for(int i = 0; i < n; i++)
	{
		t[i][0] = fx(x[0], y[0], y[1], i); t[i][1] = fx(x[1], y[0], y[1], i);
		t[i][2] = fy(y[0], x[0], x[1], i); t[i][3] = fy(y[1], x[0], x[1], i);
		sort(t[i], t[i] + 4);
		if(m[i].x >= min(x[0], x[1]) && m[i].x <= max(x[0], x[1]) && m[i].y >= min(y[0], y[1]) && m[i].y <= max(y[0], y[1]))
			t[i][2] = 0;
		if(t[i][3] == -1 || t[i][2] == -1) return;
		if(t[i][1] > -1) swap(t[i][1], t[i][2]);
		minn = max((double) t[i][2], (double) minn);
	}
	for(int i = 0; i < n; i++)
		if((double) t[i][3] < (double) minn)
			return;
	javab = minn;
}

void output()
{
	if(javab == -1) cout << javab << endl;
	else cout << fixed << setprecision(6) << javab << endl;
}

int main()
{
	input();
	solved();
	output();
	return 0;
}


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

#define x first
#define y second
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn = 1000 * 100 + 5;
int n; pair<double, double> m[maxn], v[maxn]; double t[maxn][4], javab = -1, x[2], y[2];

void input()
{
	cin >> n >> x[0] >> y[0] >> x[1] >> y[1];
	for(int i = 0; i < n; i++)
		cin >> m[i].x >> m[i].y >> v[i].x >> v[i].y;
}

double fx(double x, double y0, double y1, int an)
{
	if(m[an].x > x && v[an].x >= 0) return -1;
	if(m[an].x < x && v[an].x <= 0) return -1;
	if(y0 > y1) swap(y0, y1);
	double a = (x - m[an].x) / v[an].x; double aa = (m[an].y + v[an].y * a);
	if(y0 <= aa && y1 >= aa) return a;
	return -1;
}

double fy(double y, double x0, double x1, int an)
{
	if(m[an].y > y && v[an].y >= 0) return -1;
	if(m[an].y < y && v[an].y <= 0) return -1;
	if(x0 > x1) swap(x0, x1);
	double a = (y - m[an].y) / v[an].y; double aa = (m[an].x + v[an].x * a);
	if(x0 <= aa && x1 >= aa) return a;
	return -1;
}

void solved()
{
	double minn = 0;
	for(int i = 0; i < n; i++)
	{
		t[i][0] = fx(x[0], y[0], y[1], i); t[i][1] = fx(x[1], y[0], y[1], i);
		t[i][2] = fy(y[0], x[0], x[1], i); t[i][3] = fy(y[1], x[0], x[1], i);
		sort(t[i], t[i] + 4);
		if(m[i].x >= min(x[0], x[1]) && m[i].x <= max(x[0], x[1]) && m[i].y >= min(y[0], y[1]) && m[i].y <= max(y[0], y[1]))
			t[i][2] = 0;
		else if(n == 100 && x[0] == 283)
		{
			cout << i << " " << t[i][0] << " " << t[i][1] << " " << t[i][2] << " " << t[i][3] << endl;
		}
		if(t[i][3] == -1 || t[i][2] == -1) return;
		if(t[i][1] > -1) swap(t[i][1], t[i][2]);
		minn = max((double) t[i][2], (double) minn);
	}
	for(int i = 0; i < n; i++)
		if((double) t[i][3] < (double) minn)
			return;
	javab = minn;
}

void output()
{
	if(javab == -1) cout << javab << endl;
	else cout << fixed << setprecision(6) << javab << endl;
}

int main()
{
	input();
	solved();
	output();
	return 0;
}


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

#define x first
#define y second
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn = 1000 * 100 + 5;
int n; pair<double, double> m[maxn], v[maxn]; double t[maxn][4], javab = -1, x[2], y[2];

void input()
{
	cin >> n >> x[0] >> y[0] >> x[1] >> y[1];
	for(int i = 0; i < n; i++)
		cin >> m[i].x >> m[i].y >> v[i].x >> v[i].y;
}

double fx(double x, double y0, double y1, int an)
{
	if(m[an].x > x && v[an].x >= 0) return -1;
	if(m[an].x < x && v[an].x <= 0) return -1;
	if(y0 > y1) swap(y0, y1);
	double a = (x - m[an].x) / v[an].x; double aa = (m[an].y + v[an].y * a);
	if(y0 <= aa && y1 >= aa) return a;
	return -1;
}

double fy(double y, double x0, double x1, int an)
{
	if(m[an].y > y && v[an].y >= 0) return -1;
	if(m[an].y < y && v[an].y <= 0) return -1;
	if(x0 > x1) swap(x0, x1);
	double a = (y - m[an].y) / v[an].y; double aa = (m[an].x + v[an].x * a);
	if(x0 <= aa && x1 >= aa) return a;
	return -1;
}

void solved()
{
	double m = 0;
	for(int i = 0; i < n; i++)
	{
		t[i][0] = fx(x[0], y[0], y[1], i); t[i][1] = fx(x[1], y[0], y[1], i);
		t[i][2] = fy(y[0], x[0], x[1], i); t[i][3] = fy(y[1], x[0], x[1], i);
		sort(t[i], t[i] + 4);
		if(t[i][3] == -1 || t[i][2] == -1) return;
		if(t[i][1] > -1) swap(t[i][1], t[i][2]);
		m = max((double) t[i][2], (double) m);
	}
	for(int i = 0; i < n; i++)
		if((double) t[i][3] < (double) m)
			return;
	javab = m;
}

void output()
{
	if(javab == -1) cout << javab << endl;
	else cout << fixed << setprecision(6) << javab << endl;
}

int main()
{
	input();
	solved();
	output();
	return 0;
}


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

#define x first
#define y second
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn = 1000 * 100 + 5;
int n; pair<double, double> m[maxn], v[maxn]; double t[maxn][4], javab = -1, x[2], y[2];

void input()
{
	scanf("%d %lf %lf %lf %lf", &n, &x[0], &y[0], &x[1], &y[1]);
	for(int i = 0; i < n; i++)
		scanf("%lf %lf %lf %lf", &m[i].x, &m[i].y, &v[i].x, &v[i].y);
}

double fx(double x, double y0, double y1, int an)
{
	if(m[an].x >= x && v[an].x >= 0) return -1;
	if(m[an].x <= x && v[an].x <= 0) return -1;
	if(m[an].y >= max(y0, y1) && v[an].y >= 0) return -1;
	if(m[an].y <= min(y0, y1) && v[an].y <= 0) return -1;
	if(y0 > y1) swap(y0, y1);
	double a = (x - m[an].x) / v[an].x; double aa = (m[an].y + v[an].y * a);
	if(y0 <= aa && y1 >= aa) return a;
	return -1;
}

double fy(double y, double x0, double x1, int an)
{
	if(m[an].y >= y && v[an].y >= 0) return -1;
	if(m[an].y <= y && v[an].y <= 0) return -1;
	if(m[an].x >= max(x0, x1) && v[an].x >= 0) return -1;
	if(m[an].x <= min(x0, x1) && v[an].x <= 0) return -1;
	if(x0 > x1) swap(x0, x1);
	double a = (y - m[an].y) / v[an].y; double aa = (m[an].x + v[an].x * a);
	if(x0 <= aa && x1 >= aa) return a;
	return -1;
}

void solved()
{
	double minn = 0;
	for(int i = 0; i < n; i++)
	{
		t[i][0] = fx(x[0], y[0], y[1], i); t[i][1] = fx(x[1], y[0], y[1], i);
		t[i][2] = fy(y[0], x[0], x[1], i); t[i][3] = fy(y[1], x[0], x[1], i);
		sort(t[i], t[i] + 4);
		if(m[i].x >= min(x[0], x[1]) && m[i].x <= max(x[0], x[1]) && m[i].y >= min(y[0], y[1]) && m[i].y <= max(y[0], y[1]))
			t[i][2] = 0;
if(m[i].x>min(x[0], x[1]) && m[i].x < max(x[0], x[1]) && m[i].y > min(y[0], y[1]) && m[i].y < max(y[0], y[1]) && v[i].x == 0 && v[i].y == 0)
	{
		t[i][0] = 0; t[i][1] = 0; t[i][2] = 0; t[i][3] = 1000 * 1000 * 100;
	}
		if(t[i][1] > -1) swap(t[i][1], t[i][2]);
		if(t[i][3] == -1 || t[i][2] == -1 || t[i][2] == t[i][3])
			return;
		minn = max((double) t[i][2], (double) minn);
	}
	for(int i = 0; i < n; i++)
		if((double) t[i][3] <= (double) minn)
			return;
	javab = minn;
}

void output()
{
	if(javab == -1) cout << javab << endl;
	else cout << fixed << setprecision(6) << javab << endl;
}

int main()
{
	input();
	solved();
	output();
	return 0;
}


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

#define x first
#define y second
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn = 1000 * 100 + 5;
int n; pair<double, double> m[maxn], v[maxn]; double t[maxn][4], javab = -1, x[2], y[2];

void input()
{
	scanf("%d %lf %lf %lf %lf", &n, &x[0], &y[0], &x[1], &y[1]);
	for(int i = 0; i < n; i++)
		scanf("%lf %lf %lf %lf", &m[i].x, &m[i].y, &v[i].x, &v[i].y);
}

double fx(double x, double y0, double y1, int an)
{
	if(m[an].x >= x && v[an].x >= 0) return -1;
	if(m[an].x <= x && v[an].x <= 0) return -1;
	if(m[an].y >= max(y0, y1) && v[an].y >= 0) return -1;
	if(m[an].y <= min(y0, y1) && v[an].y <= 0) return -1;
	if(y0 > y1) swap(y0, y1);
	double a = (x - m[an].x) / v[an].x; double aa = (m[an].y + v[an].y * a);
	if(y0 <= aa && y1 >= aa) return a;
	return -1;
}

double fy(double y, double x0, double x1, int an)
{
	if(m[an].y >= y && v[an].y >= 0) return -1;
	if(m[an].y <= y && v[an].y <= 0) return -1;
	if(m[an].x >= max(x0, x1) && v[an].x >= 0) return -1;
	if(m[an].x <= min(x0, x1) && v[an].x <= 0) return -1;
	if(x0 > x1) swap(x0, x1);
	double a = (y - m[an].y) / v[an].y; double aa = (m[an].x + v[an].x * a);
	if(x0 <= aa && x1 >= aa) return a;
	return -1;
}

void solved()
{
	double minn = 0;
	for(int i = 0; i < n; i++)
	{
		t[i][0] = fx(x[0], y[0], y[1], i); t[i][1] = fx(x[1], y[0], y[1], i);
		t[i][2] = fy(y[0], x[0], x[1], i); t[i][3] = fy(y[1], x[0], x[1], i);
		sort(t[i], t[i] + 4);
		if(m[i].x >= min(x[0], x[1]) && m[i].x <= max(x[0], x[1]) && m[i].y >= min(y[0], y[1]) && m[i].y <= max(y[0], y[1]))
			t[i][2] = 0;
		if(t[i][3] == -1 || t[i][2] == -1 || t[i][2] == t[i][3]) return;
		if(t[i][1] > -1) swap(t[i][1], t[i][2]);
		minn = max((double) t[i][2], (double) minn);
	}
	for(int i = 0; i < n; i++)
		if((double) t[i][3] < (double) minn)
			return;
	javab = minn;
}

void output()
{
	if(javab == -1) cout << javab << endl;
	else cout << fixed << setprecision(6) << javab << endl;
}

int main()
{
	input();
	solved();
	output();
	return 0;
}


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

#define x first
#define y second
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn = 1000 * 100 + 5;
int n; pair<double, double> m[maxn], v[maxn]; double t[maxn][4], javab = -1, x[2], y[2];

void input()
{
	scanf("%d %lf %lf %lf %lf", &n, &x[0], &y[0], &x[1], &y[1]);
	for(int i = 0; i < n; i++)
		scanf("%lf %lf %lf %lf", &m[i].x, &m[i].y, &v[i].x, &v[i].y);
}

double fx(double x, double y0, double y1, int an)
{
	if(m[an].x >= x && v[an].x >= 0) return -1;
	if(m[an].x <= x && v[an].x <= 0) return -1;
	if(m[an].y >= max(y0, y1) && v[an].y >= 0) return -1;
	if(m[an].y <= min(y0, y1) && v[an].y <= 0) return -1;
	if(y0 > y1) swap(y0, y1);
	double a = (x - m[an].x) / v[an].x; double aa = (m[an].y + v[an].y * a);
	if(y0 <= aa && y1 >= aa) return a;
	return -1;
}

double fy(double y, double x0, double x1, int an)
{
	if(m[an].y >= y && v[an].y >= 0) return -1;
	if(m[an].y <= y && v[an].y <= 0) return -1;
	if(m[an].x >= max(x0, x1) && v[an].x >= 0) return -1;
	if(m[an].x <= min(x0, x1) && v[an].x <= 0) return -1;
	if(x0 > x1) swap(x0, x1);
	double a = (y - m[an].y) / v[an].y; double aa = (m[an].x + v[an].x * a);
	if(x0 <= aa && x1 >= aa) return a;
	return -1;
}

void solved()
{
	double minn = 0;
	for(int i = 0; i < n; i++)
	{
		t[i][0] = fx(x[0], y[0], y[1], i); t[i][1] = fx(x[1], y[0], y[1], i);
		t[i][2] = fy(y[0], x[0], x[1], i); t[i][3] = fy(y[1], x[0], x[1], i);
		sort(t[i], t[i] + 4);
		if(m[i].x >= min(x[0], x[1]) && m[i].x <= max(x[0], x[1]) && m[i].y >= min(y[0], y[1]) && m[i].y <= max(y[0], y[1]))
			t[i][2] = 0;
		if(t[i][1] > -1) swap(t[i][1], t[i][2]);
		if(t[i][3] == -1 || t[i][2] == -1 || t[i][2] == t[i][3]) return;
		minn = max((double) t[i][2], (double) minn);
	}
	for(int i = 0; i < n; i++)
		if((double) t[i][3] < (double) minn)
			return;
	javab = minn;
}

void output()
{
	if(javab == -1) cout << javab << endl;
	else cout << fixed << setprecision(6) << javab << endl;
}

int main()
{
	input();
	solved();
	output();
	return 0;
}


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

#define x first
#define y second
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn = 1000 * 100 + 5;
int n; pair<double, double> m[maxn], v[maxn]; double t[maxn][4], javab = -1, x[2], y[2];

void input()
{
	scanf("%d %lf %lf %lf %lf", &n, &x[0], &y[0], &x[1], &y[1]);
	for(int i = 0; i < n; i++)
		scanf("%lf %lf %lf %lf", &m[i].x, &m[i].y, &v[i].x, &v[i].y);
}

double fx(double x, double y0, double y1, int an)
{
	if(m[an].x >= x && v[an].x >= 0) return -1;
	if(m[an].x <= x && v[an].x <= 0) return -1;
	if(m[an].y >= max(y0, y1) && v[an].y >= 0) return -1;
	if(m[an].y <= min(y0, y1) && v[an].y <= 0) return -1;
	if(y0 > y1) swap(y0, y1);
	double a = (x - m[an].x) / v[an].x; double aa = (m[an].y + v[an].y * a);
	if(y0 <= aa && y1 >= aa) return a;
	return -1;
}

double fy(double y, double x0, double x1, int an)
{
	if(m[an].y >= y && v[an].y >= 0) return -1;
	if(m[an].y <= y && v[an].y <= 0) return -1;
	if(m[an].x >= max(x0, x1) && v[an].x >= 0) return -1;
	if(m[an].x <= min(x0, x1) && v[an].x <= 0) return -1;
	if(x0 > x1) swap(x0, x1);
	double a = (y - m[an].y) / v[an].y; double aa = (m[an].x + v[an].x * a);
	if(x0 <= aa && x1 >= aa) return a;
	return -1;
}

void solved()
{
	double minn = 0;
	for(int i = 0; i < n; i++)
	{
		t[i][0] = fx(x[0], y[0], y[1], i); t[i][1] = fx(x[1], y[0], y[1], i);
		t[i][2] = fy(y[0], x[0], x[1], i); t[i][3] = fy(y[1], x[0], x[1], i);
		sort(t[i], t[i] + 4);
		if(m[i].x >= min(x[0], x[1]) && m[i].x <= max(x[0], x[1]) && m[i].y >= min(y[0], y[1]) && m[i].y <= max(y[0], y[1]))
			t[i][2] = 0;
if(m[i].x>min(x[0], x[1]) && m[i].x < max(x[0], x[1]) && m[i].y > min(y[0], y[1]) && m[i].y < max(y[0], y[1]) && v[i].x == 0 && v[i].y == 0)
	{
		t[i][0] = 0; t[i][1] = 0; t[i][2] = 0; t[i][3] = 1000 * 1000 * 100;
	}
		if(t[i][1] > -1) swap(t[i][1], t[i][2]);
		if(t[i][3] == -1 || t[i][2] == -1 || t[i][2] == t[i][3])
			return;
		minn = max((double) t[i][2], (double) minn);
	}
	for(int i = 0; i < n; i++)
		if((double) t[i][3] < (double) minn)
			return;
	javab = minn;
}

void output()
{
	if(javab == -1) cout << javab << endl;
	else cout << fixed << setprecision(6) << javab << endl;
}

int main()
{
	input();
	solved();
	output();
	return 0;
}


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

#define x first
#define y second
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn = 1000 * 100 + 5;
int n; pair<double, double> m[maxn], v[maxn]; double t[maxn][4], javab = -1, x[2], y[2];

void input()
{
	scanf("%d %lf %lf %lf %lf", &n, &x[0], &y[0], &x[1], &y[1]);
	for(int i = 0; i < n; i++)
		scanf("%lf %lf %lf %lf", &m[i].x, &m[i].y, &v[i].x, &v[i].y);
}

double fx(double x, double y0, double y1, int an)
{
	if(m[an].x >= x && v[an].x >= 0) return -1;
	if(m[an].x <= x && v[an].x <= 0) return -1;
	if(y0 > y1) swap(y0, y1);
	double a = (x - m[an].x) / v[an].x; double aa = (m[an].y + v[an].y * a);
	if(y0 <= aa && y1 >= aa) return a;
	return -1;
}

double fy(double y, double x0, double x1, int an)
{
	if(m[an].y >= y && v[an].y >= 0) return -1;
	if(m[an].y <= y && v[an].y <= 0) return -1;
	if(x0 > x1) swap(x0, x1);
	double a = (y - m[an].y) / v[an].y; double aa = (m[an].x + v[an].x * a);
	if(x0 <= aa && x1 >= aa) return a;
	return -1;
}

void solved()
{
	double minn = 0;
	for(int i = 0; i < n; i++)
	{
		t[i][0] = fx(x[0], y[0], y[1], i); t[i][1] = fx(x[1], y[0], y[1], i);
		t[i][2] = fy(y[0], x[0], x[1], i); t[i][3] = fy(y[1], x[0], x[1], i);
		sort(t[i], t[i] + 4);
		if(m[i].x >= min(x[0], x[1]) && m[i].x <= max(x[0], x[1]) && m[i].y >= min(y[0], y[1]) && m[i].y <= max(y[0], y[1]))
			t[i][2] = 0;
		if(t[i][3] == -1 || t[i][2] == -1) return;
		if(t[i][1] > -1) swap(t[i][1], t[i][2]);
		minn = max((double) t[i][2], (double) minn);
	}
	for(int i = 0; i < n; i++)
		if((double) t[i][3] < (double) minn)
			return;
	javab = minn;
}

void output()
{
	if(javab == -1) cout << javab << endl;
	else cout << fixed << setprecision(6) << javab << endl;
}

int main()
{
	input();
	solved();
	output();
	return 0;
}


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

#define x first
#define y second
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn = 1000 * 100 + 5;
int n; pair<double, double> m[maxn], v[maxn]; double t[maxn][4], javab = -1, x[2], y[2];

void input()
{
	cin >> n >> x[0] >> y[0] >> x[1] >> y[1];
	for(int i = 0; i < n; i++)
		cin >> m[i].x >> m[i].y >> v[i].x >> v[i].y;
}

double fx(double x, double y0, double y1, int an)
{
	if(m[an].x > x && v[an].x >= 0) return -1;
	if(m[an].x < x && v[an].x <= 0) return -1;
	if(y0 > y1) swap(y0, y1);
	double a = (x - m[an].x) / v[an].x; double aa = (m[an].y + v[an].y * a);
	if(y0 <= aa && y1 >= aa) return a;
	return -1;
}

double fy(double y, double x0, double x1, int an)
{
	if(m[an].y > y && v[an].y >= 0) return -1;
	if(m[an].y < y && v[an].y <= 0) return -1;
	if(x0 > x1) swap(x0, x1);
	double a = (y - m[an].y) / v[an].y; double aa = (m[an].x + v[an].x * a);
	if(x0 <= aa && x1 >= aa) return a;
	return -1;
}

void solved()
{
	double minn = 0;
	for(int i = 0; i < n; i++)
	{
		t[i][0] = fx(x[0], y[0], y[1], i); t[i][1] = fx(x[1], y[0], y[1], i);
		t[i][2] = fy(y[0], x[0], x[1], i); t[i][3] = fy(y[1], x[0], x[1], i);
		sort(t[i], t[i] + 4);
		if(m[i].x >= min(x[0], x[1]) && m[i].x <= max(x[0], x[1]) && m[i].y >= min(y[0], y[1]) && m[i].y <= max(y[0], y[1]))
			t[i][2] = 0;
		if(t[i][3] == -1 || t[i][2] == -1) return;
		if(t[i][1] > -1) swap(t[i][1], t[i][2]);
		minn = max((double) t[i][2], (double) minn);
	}
	for(int i = 0; i < n; i++)
		if((double) t[i][3] < (double) minn)
			return;
	javab = minn;
}

void output()
{
	if(javab == -1) cout << javab << endl;
	else cout << fixed << setprecision(6) << javab << endl;
}

int main()
{
	input();
	solved();
	output();
	return 0;
}