#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000007;
ll infl=1000000000000000007;
int mod=1000000007;
int mod1=998244353;
const int N=307;
int r,c,n;
int ans=inf;
int x[N],y[N];
void check(int U,int D)
{
set<pair<int,int>>X;
vector<pair<int,int>>E;
int S=0,L=0,R=0;
for(int i=1;i<=n;i++)
{
if(max(1,x[i]-D)==1) X.insert({y[i],i});
else E.pb({max(1,x[i]-D),-i});
if(min(r,x[i]+U)<r) E.pb({min(r,x[i]+U)+1,i});
}
if(sz(X)==0) return ;
R=(*X.begin()).st-1;
L=c-(*--X.end()).st;
int last=-1;
for(auto [Y,i]:X)
{
if(last!=-1) S=max(S,Y-last-1);
last=Y;
}
X.insert({-inf,0});
X.insert({inf,0});
sort(all(E));
for(auto [t,i]:E)
{
if(i<0) X.insert({y[-i],-i});
else
{
X.erase({y[i],i});
if(sz(X)==2) return ;
int LL=(*--X.upper_bound({y[i],0})).st;
int RR=(*X.upper_bound({y[i],0})).st;
if(LL==-inf) R=max(R,RR-1);
if(RR==inf) L=max(L,c-LL);
if(LL!=-inf&&RR!=inf) S=max(S,RR-LL-1);
}
}
ans=min(ans,U+D+max(S,R+L));
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>r>>c>>n;
for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
set<int>cnd;
cnd.insert(0);
for(int i=1;i<=n;i++)
{
cnd.insert(x[i]-1);
cnd.insert(r-x[i]);
for(int j=1;j<=n;j++) cnd.insert(abs(x[i]-x[j])-1);
}
for(auto i:cnd) for(auto j:cnd) check(i,j);
cout<<ans;
return 0;
}
/*
4 4
4
1 1
1 4
4 1
4 4
*/