#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define sgn(v) (abs((v))<eps?0:((v)<0?-1:1))
#define sqr(v) ((v)*(v))
#define tri(v) ((v)*(v)*(v))
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
using namespace std;
typedef long long LL;
typedef long double Double;
typedef unsigned long long ULL;
typedef pair<double,int> PDI;
typedef pair<double,double> PDD;
typedef pair<int,int> PII;
typedef pair<int,LL> PIL;
typedef pair<LL,int> PLI;
typedef pair<LL,LL> PLL;
const double eps=1e-8;
const double pi=acos(-1);
const int maxn=3000;
bool mp[55][55][55][55];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
struct Edge
{
	int v,next;
}edge[maxn*4];
int head[maxn],ne;
void add(int u,int v)
{
	edge[ne].v=v;
	edge[ne].next=head[u];
	head[u]=ne++;
}
queue<int> q;
bool inq[maxn];
int ix,iy,ox,oy,w,h;
int dis[maxn];
const int inf=1e9;
void construct(int debug=0)
{
	int i,j,k,x,y;
	memset(head,-1,sizeof(head));
	ne=0;
	for(i=0;i<w;++i)
		for(j=0;j<h;++j)
			for(k=0;k<4;++k)
			{
				x=i+dx[k];
				y=j+dy[k];
				if(x<0||x==w||y<0||y==h)continue;
				//if(debug&&i==0&&j==0&&x==0&&y==1)cout <<"mp:"<<mp[i][j][x][y]<<endl;
				//if(debug&&i==0&&j==0&&x==1&&y==0)cout <<"mp:"<<mp[i][j][x][y]<<endl;
				if(!mp[i][j][x][y])add(i*h+j,x*h+y);
			}
}
int bfs(int debug=0)
{
	int u,v,x,y,i;
	for(i=0;i<w*h;++i)dis[i]=inf;
	u=ix*h+iy;
	dis[u]=0;
	q.push(u);
	inq[u]=true;
	while(!q.empty())
	{
		u=q.front();
		inq[u]=false;
		q.pop();
		x=u/h;
		y=u%h;
		if(debug)
		{
			cout <<x<<" "<<y<<" "<<dis[u]<<endl;getchar();
		}
		for(i=head[u];i!=-1;i=edge[i].next)
		{
			v=edge[i].v;
			if(dis[u]+1<dis[v])
			{
				dis[v]=dis[u]+1;
				if((x!=ox||y!=oy)&&(!inq[v]))
				{
					inq[v]=true;
					q.push(v);
				}
			}
		}
	}
	//if(debug)cout <<ox*h+oy<<endl;
	return dis[ox*h+oy];
}
int main()
{
	int n,i,j,sx,sy,dx,dy;
	scanf("%d%d%d",&w,&h,&n);
	for(j=0;j<n;++j)
	{
		scanf("%d%d%d%d",&sx,&sy,&dx,&dy);
		//cout <<sx<<" "<<sy<<" "<<dx<<" "<<dy<<endl;
		if(sx==dx&&sx>0)
		{
			if(sy>dy)swap(sy,dy);
			for(i=sy;i<dy;++i)
			{
				mp[sx-1][i][sx][i]=true;
				mp[sx][i][sx-1][i]=true;
			}
		}
		else if(sy==dy&&sy>0)
		{
			if(sx>dx)swap(sx,dx);
			for(i=sx;i<dx;++i)
			{
				mp[i][sy-1][i][sy]=true;
				mp[i][sy][i][sy-1]=true;
			}
		}
	}
	//cout <<mp[1][0][1][1]<<endl;
	scanf("%d%d",&ix,&iy);
	scanf("%d%d",&ox,&oy);
	construct();
	int ans=bfs(),maxv,res;
	maxv=ans;
	//cout <<"Here:"<<ans<<endl;
	for(i=1;i<w;++i)
		for(j=0;j<h;++j)
			if(!mp[i-1][j][i][j])
			{
				mp[i-1][j][i][j]=mp[i][j][i-1][j]=true;
				construct();
				res=bfs();
				if(res!=inf)maxv=max(maxv,res);
				mp[i-1][j][i][j]=mp[i][j][i-1][j]=false;
			}
	for(j=1;j<h;++j)
		for(i=0;i<w;++i)
			if(!mp[i][j-1][i][j])
			{
				mp[i][j-1][i][j]=mp[i][j][i][j-1]=true;
				construct();
				res=bfs();
				if(res!=inf)maxv=max(maxv,res);
				mp[i][j-1][i][j]=mp[i][j][i][j-1]=false;
			}
	//cout <<ans<<" "<<maxv<<endl;
	if(maxv==inf)puts("0");
	else printf("%d\n",maxv-ans);
	return 0;
}

Measured memory_bytes: 9376