#include <iostream>
#include <algorithm>
using namespace std;
 
int distance(int a, int b, int c, int d) {
	int ans = 0;
	if (a > b) {
		swap(a, b);
	}
	if (c > d) {
		swap(c, d);
	}
	if (b < c || a > d) {
		ans = 0;
	} 
	else {
		int l = 0, r = 0;
		l = max(a, c);
		r = min(b, d);
		ans = r - l;
	}
	return ans;
}
 
int main() {
	int x1, y1, x2, y2, x3, y3, x4, y4;
	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
	if (x1 != x2) {
		cout << (y1 < max(y3, y4) && y1 > min(y3, y4) ? distance(x1, x2, x3, x4) : 0); 
	}
	else {
		cout << (x1 < max(x3, x4) && x1 > min(x3, x4) ? distance(y1, y2, y3, y4) : 0);
	}
	return 0;
}