// |--------------------------------------------|
// | User - Kunal Kumar                         |
// |--------------------------------------------| 

#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define pf push_front
#define ppf pop_front
#define pii pair<int,int>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define ulli unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vulli vector<ulli>
#define vb vector<bool>
#define vpii vector<pii>
#define vpll vector<pll>
#define mod 1000000007
#define F first
#define S second
#define NN 200001
#define modu 998244353
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define INF 1e18
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll
#define endl "\n"
using namespace std;
 
int gcd(int a, int b)
{
    if(b==0)
        return a;
    
    return gcd(b,a%b);
}

//seive
bool prime_num[1000001];
void SOE(vector <int> &v)
{
    int n = 1000000;
    memset(prime_num, true, sizeof(prime_num));
 
    for (int p = 2; p * p <= n; p++)
    {
        if (prime_num[p] == true) 
        {
            for (int i = p * p; i <= n; i += p)
                prime_num[i] = false;
        }
    }
    
    
    for (int p = 2; p <= n; p++)
        if (prime_num[p])
            v.pb(p);
}
 
bool binary_search(vector <int> v,int s, int e,int num)
{
    while(s<=e)
    {
        int mid=(s+(e-s)/2);
        
        if(v[mid]==num)
            return true;
        else
        if(v[mid]>num)
            e=mid-1;
        else
            s=mid+1;
    }
    
    return false;
}
 
ll power(ll x, ll y, ll p)
{
    ll res = 1; 
    x = x % p; 
    while (y > 0) 
    {     
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
 
ll modInverse(ll n,ll p)
{
    return power(n, p - 2, p);
    
    /*
    ll inv[maxn],finv[maxn];
    inv[1] =inv[0]= 1;
    finv[0]=finv[1]=1;
    for (int i=2; i<maxn; ++i)
        inv[i] = (m - (m/i) * inv[m%i] % m) % m;
        
    for (int i=2;i<maxn;++i){
        finv[i]=(inv[i]%m * finv[i-1]%m)%m;
    }

    */
}
 
ll factorial[200001];
ll nCr(ll n, ll r, ll p)
{
    if (n < r)
        return 0;
    if (r == 0)
        return 1;
 
    return (factorial[n] * (modInverse(factorial[r], p) % p) * (modInverse(factorial[n - r], p) % p))% p;
}

void addEdge(vector <int> G[], int s, int e )
{
    G[s].pb(e);
    G[e].pb(s);
}


void solve()
{
    ll n;
    cin>>n;
    
    vl A(n),B(n);
    rep(i,0,n)
        cin>>A[i];
    
    rep(i,0,n)
        cin>>B[i];
        
    ll maxA = A[0], minB = B[0];
    
    rep(i,1,n)
    {
        if(maxA<A[i])
            maxA = A[i];
        if(minB>B[i])
            minB = B[i];
    }
    if(maxA>minB)
    {
        cout<<0;
        return;
    }
    
    cout<<(minB-maxA+1);
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    int t;
    t=1;
    //cin>>t;

    while(t--)
    {
        solve();
    }

}



// Keep Hustling!!!!!!!!!!!
// #MerinoNoMeRepresenta
#include<bits/stdc++.h> 
#define fp(x,a,b) for(ll x=a; x<b; x++)
#define fn(x,a,b) for(int x=a; x>b; x--)
#define f(x, m) for(auto x : m)
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int ,int>>
#define vll vector<pair<ll ,ll>>
#define all(v) v.begin(),v.end()
#define sor(a) sort( a.begin(), a.end() )
#define ros(a) sort( a.rbegin(), a.rend())
#define prec(n) fixed<<setprecision(n)
#define ff first
#define ss second
// #define tt third
#define print(x) for(auto it:x) cout<<it<<" ";
#define debug(x) cerr << #x << " is " << x << endl;
#define w(x) while(x--)
#define r(x) scanf("%d", &x)
#define rl(x) scanf("%ld", &x) 
#define rll(x) scanf("%lld", &x)
typedef long long ll;
using namespace std;
template <typename TYPE> void readint(TYPE &x){
x=0; int f=1; char c;
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=x*10+c-'0';
x*=f;
}
#define error(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
template<typename... T>
void read(T& ... args){
  ((cin >> args), ...);
}
template<typename... T>
void write(T ... args){
  ((cout << args << ' '), ...);
  cout<<'\n';
}
const ll MOD = 1e9 + 7, MOD1 = 998244353LL, MAX = 3e3 + 5;
const char nl = '\n';
const int INF = 2e9;
int n, k;
//queue front back push pop
//stack top push pop
ll dp[MAX][MAX];
 ll sol(int n, int k){
  if (n < k) return 0LL;
  if(dp[n][k] != -1) return dp[n][k];
  if (n == k) return 1LL; 
  if(k == 0) return 0LL;
  dp[n][k] = (sol(n - 1, k - 1) + sol(n, k * 2))%MOD1;
  return dp[n][k];
  //This belongs to Maestro_Koldo
}
void solve(){
  read(n, k);
  fp(i, 0, MAX) fp(j, 0, MAX) dp[i][j] = -1LL;
  write(sol(n, k));
  
}
int main(){
cpu();
// int __;
//  cin>>__;
//  while(__--){
//   solve();
//   // cout << nl;
//  }
   solve();
// cout<<nl;
 
return 0;
}