#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmludCBkaXN0YW5jZShpbnQgYSwgaW50IGIsIGludCBjLCBpbnQgZCkgewoJaW50IGFucyA9IDA7CglpZiAoYSA+IGIpIHsKCQlzd2FwKGEsIGIpOwoJfQoJaWYgKGMgPiBkKSB7CgkJc3dhcChjLCBkKTsKCX0KCWlmIChiIDwgYyB8fCBhID4gZCkgewoJCWFucyA9IDA7Cgl9IAoJZWxzZSB7CgkJaW50IGwgPSAwLCByID0gMDsKCQlsID0gbWF4KGEsIGMpOwoJCXIgPSBtaW4oYiwgZCk7CgkJYW5zID0gciAtIGw7Cgl9CglyZXR1cm4gYW5zOwp9CiAKaW50IG1haW4oKSB7CglpbnQgeDEsIHkxLCB4MiwgeTIsIHgzLCB5MywgeDQsIHk0OwoJY2luID4+IHgxID4+IHkxID4+IHgyID4+IHkyID4+IHgzID4+IHkzID4+IHg0ID4+IHk0OwoJaWYgKHgxICE9IHgyKSB7CgkJY291dCA8PCAoeTEgPCBtYXgoeTMsIHk0KSAmJiB5MSA+IG1pbih5MywgeTQpID8gZGlzdGFuY2UoeDEsIHgyLCB4MywgeDQpIDogMCk7IAoJfQoJZWxzZSB7CgkJY291dCA8PCAoeDEgPCBtYXgoeDMsIHg0KSAmJiB4MSA+IG1pbih4MywgeDQpID8gZGlzdGFuY2UoeTEsIHkyLCB5MywgeTQpIDogMCk7Cgl9CglyZXR1cm4gMDsKfQ==