#include <iostream>
#include<cmath>
#define maxn 105
#define maxm 100005
bool black[maxn][maxm];
int d[maxn];
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int req;
    cin>>req;
    int x1,x2,y1,y2;
    for(int i=0; i < req; i ++)
    {
        cin>>x1>>y1>>x2>>y2;
        // horizontal line
        if(x1==x2)
        {
            for(int q = y1-1; q <= y2-1; q++)
                black[x1-1][q] = true;

        }
        // vertical line
        else
        {
            for(int q = x1-1; q <= x2-1; q++)
                black[q][y1-1] = true;

        }
    }

    int minnum = 0, len = 0, res = 0;
    for(int j = 0 ; j < m; j++)
    {
        minnum = 0;
        len = 0;
        for(int i = 0 ; i < n; i++)
        {
            if(black[i][j])
            {
                d[i] = 0;
                len = 0;
                minnum = 0;
            }
            else
            {
                d[i]++;
                len++;
                if(d[i] < minnum && minnum != 0)
                    minnum = d[i];
                if(minnum == 0)
                    minnum = d[i];
                if(len > minnum && minnum > res){
                    res = minnum;
                }
                if(minnum >= len && len > res)
                    res = len;
            }
        }
    }

    cout<<res<<endl;
    return 0;
}


/*

6 5
4
1 2 1 5
1 4 5 4
5 2 5 2
1 2 1 5

8 8
8
1 2 3 2
2 5 2 8
5 3 5 8
4 4 8 4
7 2 7 2
5 1 5 5
7 5 7 5
7 7 7 7

2 2
4
1 1 1 1
1 2 1 2
2 1 2 1
2 2 2 2


*/

