#include<bits/stdc++.h>
using namespace std;
#define ints(...)		int __VA_ARGS__; vin(__VA_ARGS__)
#define dbls(...)		double __VA_ARGS__; vin(__VA_ARGS__)
#define ulls(...) 		unsigned long long __VA_ARGS__; vin(__VA_ARGS__)
#define strs(...) 		string __VA_ARGS__; vin(__VA_ARGS__)
#define vifin(x, y)		vi x(y); fin(x, y)
#define vvis(x, y, z, p)vvi x(y, vi(z, p))
#define deb 			cout << "<deb> DEB" << endl
#define debi(x) 		cout << "<deb> " << #x << " == " << x << endl
#define rep(x, y) 		for(int x = 0; x < y; x++)
#define reps(x, y, z)	for(int x = y; x < z; x++)
#define rev(x, y)		for(int x = y; x >= 0; x--)
#define revs(x, y, z)	for(int x = y; x >= z; x--)
#define syz(x) 			(int)x.size()
#define ptg(x, y)		(sqrt((x*x)+(y*y)))
#define all(x) 			x.begin(), x.end()
#define will(x) 		do{cout << x << endl; return 0;}while(0)
using ll 	= long long;
using ull	= unsigned long long;
using str	= string;
using vi 	= vector<int>;
using vc 	= vector<char>;
using vs	= vector<str>;
using vvi	= vector<vector<int>>;
using vvc	= vector<vector<char>>;
using pi	= pair<int, int>;
template<class T> using v = vector<T>;
template<class T> using pq = priority_queue<T>;
void vin(){return;}
template<class T>void fin(T& __x,int __y){rep(i, __y){cin >>__x[i];};}
void lout(){cout<<"=============================================="<<endl;}
template<class T>void fout(T& __x){cout<<"<deb> ";for(auto __y:__x){cout<< __y<<' ';}cout<<endl;}
template<class T>void fout(T& __x,int __y){cout<<"<deb> ";rep(i,__y)cout <<__x[i]<<' ';cout<<endl;}
template<class T>void ffout(T __x){lout();for(auto __y:__x){for(auto __z:__y){cout<<__z<<' ';}cout<<endl;}}
template<class T>void ffout(T __x,int __y,int __z){lout();rep(i,__y){rep(j,__z)cout<<__x[i][j]<<' ';cout<<endl;}lout();}
template<class C,class ...T>inline void vin(C& __f,T&... __x){cin >> __f;vin(__x...);}
template<class T>inline void chmax(T &a,const T &b){if(a<b)a=b;}
template<class T>inline void chmin(T &a,const T &b){if(b<a)a=b;}
constexpr ull LINF	= 4500000000000000000;
constexpr int INF 	= 2000000000;
constexpr int four	= 10007		;
constexpr int five	= 100007	;
constexpr int six	= 1000007	;
constexpr int seven	= 10000007	;
constexpr int eight	= 100000007	;
constexpr int nine	= 1000000007;

signed main() {
	ints(a, b, c, d);
	int sum = -INF;
	reps(i, a, b+1) {
		reps(j, c, d+1) {
			chmax(sum, i-j);
		}
	}
	cout << sum << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
typedef pair<ll,ll> P;

ll a,b,c;
int main(){
    cin>>a>>b>>c;
    a%=10;
    b%=20;
    c%=4;
    if(c==0)c=4;
    ll d=(ll)pow(b,c)%4;
    if(d==0)d=4;
    ll an=(ll)pow(a,d)%10;
    cout<<an<<endl;
}