#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
int wall[51][51][51][51] = {0};
int W, H;
bool inRange(int x, int y) {
	return 0 <= x && x < W && 0 <= y && y < H;
}
bool inRange(P p) {
	int x, y; tie(x, y) = p;
	return inRange(x, y);
}
ll bfs(P s, P t) {
	ll dist[51][51]; fill(dist[0], dist[51], linf); dist[s.second][s.first] = 0;
	queue<P> Q; Q.push(s);
	while ( !Q.empty() ) {
		P p = Q.front(); Q.pop();
		int x, y; tie(x, y) = p;
		REP(d, 4) {
			int nx = x + dx[d], ny = y + dy[d];
			if ( !inRange(nx, ny) ) continue;
			if ( wall[x][y][nx][ny] ) continue;
			if ( dist[y][x]+1 < dist[ny][nx] ) {
				dist[ny][nx] = dist[y][x]+1;
				Q.push(P(nx, ny));
			}
		}
	}
	return dist[t.second][t.first];
}
P operator-(const P& p1, const P& p2) {
	return P(p1.first-p2.first, p1.second-p2.second);
}
P operator+(const P& p1, const P& p2) {
	return P(p1.first+p2.first, p1.second+p2.second);
}
P operator/(const P& p, const int& d) {
	return P(p.first/d, p.second/d);
}
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N; cin >> W >> H >> N;
	REP(i, N) {
		int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
		P p1(x1, y1), p2(x2, y2);
		P d = p2-p1;
		d = d / (abs(d.first) + abs(d.second));
		assert( abs(d.first) + abs(d.second) == 1 );
		P p = p1;
		while (1) {
			map<P, int> m;
			FOR(x, -1, 1) FOR(y, -1, 1) {
				P p1(p.first+x, p.second+y);
				P p2(p.first+d.first+x, p.second+d.second+y);
				m[p1]++;
				m[p2]++;
			}
			vector<P> v;
			EACH(p, m) if (p.second == 2) v.pb(p.first);
			assert( v.size() == 2 );
			if (inRange(v[0]) && inRange(v[1])) {
				wall[v[0].first][v[0].second][v[1].first][v[1].second]++;
				wall[v[1].first][v[1].second][v[0].first][v[0].second]++;
			}
			p = p + d;
			if (p == p2) break;
		}
	}
	int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy;
	ll base = bfs(P(sx, sy), P(gx, gy));
	ll ans = 0;
	REP(y, H) REP(x, W) REP(d, 4) {
		int nx = x+dx[d], ny = y+dy[d];
		if ( !inRange(nx, ny) ) continue;
		++wall[x][y][nx][ny];
		++wall[nx][ny][x][y];
		ll step = bfs(P(sx, sy), P(gx, gy));
//		cout << x << " " << y << " " << nx << " " << ny << " " << step << endl;
		if (step != linf) {
			ans = max(ans, step-base);
		}
		--wall[x][y][nx][ny];
		--wall[nx][ny][x][y];
	}
	cout << ans << endl;
}

Measured memory_bytes: 14164