#include <iostream>
#include<cmath>
#define maxn 100
#define maxm 100000
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;
        x1--;
        x2--;
        y1--;
        y2--;
        // horizontal line
        if(x1==x2)
        {
            for(int q = y1; q <= y2; q++)
                black[x1][q] = true;

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

        }
    }

    int minnum = 0, len = 0, res = 1;
    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 or minnum == 0)
                    minnum = d[i];
            }

            if(min(len, minnum) > res)
            {
                res = min(len, minnum);
            }
        }

    }

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


/*

6 5
4
1 2 1 5
1 4 5 4
5 2 5 2
1 2 1 5
*/

