#include <stdio.h>
#include <stdbool.h>
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	int b[n];
	for (int i = 0; i < n; i++) b[i] = ri();
	
	int res = 0;
	for (int i = 1; i <= 1000; i++) {
		bool ok = true;
		for (int j = 0; j < n; j++) if (i < a[j] || i > b[j]) ok = false;
		if (ok) res++;
	}
	
	printf("%d\n", res);
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,j,n) for(int i=j;i<n;i++)
#define readvec(v,n) for(int i=0;i<n;i++){cin>>v[i];}
#define MOD 1000000007
vector<vector<ll>> dp;
ll rec(int x,int y)
{
  if(dp[x][y]!=-1)return dp[x][y];
  dp[x][y]=0;
  if(x>0)dp[x][y] += rec(x-1,y);
  if(y>0)dp[x][y] += rec(x,y-1);
  return dp[x][y];
}
int main()
{
  int a,b;ll k;cin>>a>>b>>k;
  dp = vector<vector<ll>>(a+1,vector<ll>(b+1,-1));
  dp[0][0] = 1;
  rec(a,b);
  string s(a+b,'x');
  //rep(i,0,a+1){rep(j,0,b+1)cout<<dp[i][j]<<" ";cout<<"\n";}
  int i=0;
  for(;i<s.size();i++)
  {
    if(k==1)break;
    if(dp[a-1][b]>=k){
      s[i]='a';a--;
    }
    else{
      s[i]='b';
      k-=dp[a-1][b];
      b--;
    }
  }
  while(a--){s[i]='a';i++;}
  while(b--){s[i]='b';i++;}
  cout<<s<<"\n";
  return 0;
}
