#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define maxw 55
#define maxn 1010

int n;
int w;
int h;
bool wall[maxw][maxw][4];
int mp[maxw][maxw];
int ix,iy;
int ox,oy;
int que[maxw*maxw][2];
int dir[4][2] = {{0,1},{1,0},{0,-1},{-1,0}};
int bfs()
{
    memset(mp,-1,sizeof(mp));
    mp[ix][iy] = 0;
    int head = 0, tail = 0;
    tail++;
    que[tail][0] = ix;
    que[tail][1] = iy;
    while (head < tail)
    {
        ++head;
        int x = que[head][0];
        int y = que[head][1];
        //printf("**********%d %d\n",x,y);
        for (int i=0;i<4;i++){
            if (!wall[x][y][i]){
                int xx = x + dir[i][0];
                int yy = y + dir[i][1];
                if (mp[xx][yy]==-1){
                 //   printf("%d %d\n",xx,yy);
                    mp[xx][yy] = mp[x][y] + 1;
                    if (xx == ox && yy == oy)
                        return mp[xx][yy];
                    tail++;
                    que[tail][0] = xx;
                    que[tail][1] = yy;
                }
            }
        }
    }
    return mp[ox][oy];
}
void init()
{
    memset(wall,0,sizeof(wall));
    for (int i=1;i<=n;i++)
    {
        int sx,sy,dx,dy;
        scanf("%d%d%d%d",&sx,&sy,&dx,&dy);
        if (sx == dx && sy == dy)
            continue ;
        if (sx == dx){
            if (sy > dy)
                swap(sy,dy);
            for (int j = max(0,sy);j<min(h,dy);j++){
                if (sx-1>=0){
                    wall[sx-1][j][1] = 1;
                }
                if (sx<w){
                    wall[sx][j][3] = 1;
                }
            }
        }
        if (sy == dy){
            if (sx > dx)
                swap(sx,dx);
            for (int j=max(sx,0);j<min(dx,w);j++){
                if (sy-1>=0){
                    wall[j][sy - 1][0] = 1;
                }
                if (sy<h){
                    wall[j][sy][2] = 1;
                }
            }
        }
    }
    for (int j=0;j<h;j++){
        wall[0][j][3] = 1;
        wall[w-1][j][1] = 1;
    }
    for (int i=0;i<w;i++){
        wall[i][0][2] = 1;
        wall[i][h-1][0] = 1;
    }
    scanf("%d%d",&ix,&iy);
    scanf("%d%d",&ox,&oy);
/*
    for (int i=0;i<=w;i++)
        for (int j=0;j<=h;j++)
            for (int k=0;k<4;k++){
                printf("%d %d %d %d\n",i,j,k,wall[i][j][k]);
            }
*/
    return ;
}
bool check(int x,int y)
{
    return (x>=0 && x<w && y>=0 && y<h);
}
int main()
{
    while (scanf("%d%d%d",&w,&h,&n)!=EOF)
    {
        init();
        if (ix==ox && iy==oy){
            puts("0");
            continue;
        }
        int tmp = bfs();
       // printf("%d\n",tmp);
        int ans = 0;
        for (int i=0;i<w;i++)
            for (int j=0;j<h;j++)
                for (int k=0;k<4;k++)
                    if (!wall[i][j][k]){
                        wall[i][j][k] = 1;
                        int ii = i + dir[k][0];
                        int jj = j + dir[k][1];
                        int kk = (k+2)%4;
                        if (check(ii,jj))
                            wall[ii][jj][kk] = 1;
                        int ttt = bfs();
                        if (ttt>=0){
                            if(ttt - tmp > ans)
                                ans = ttt - tmp;
                        }
                        wall[i][j][k] = 0;
                        if (check(ii,jj))
                            wall[ii][jj][kk] = 0;
                    }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1080