import java.util.*;
public class Main{
static int N = 1010, INF = 0x3f3f3f3f;
static int n, m, res;
static Pair q[] = new Pair[N*10];
static int p[] = new int[N*N], g[][] = new int[N][N];
static int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
for(int i = 1; i < N*N; i ++) p[i] = i;
n = sc.nextInt();
m = sc.nextInt();
for(int i = 1, t = 0; i <= n; i ++){
for(int j = 1; j <= m; j ++){
g[i][j] = ++ t; // 二维变一维
}
}
while(sc.hasNext()){
int x1 = sc.nextInt();
int y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();
int a = g[x1][y1];
int b = g[x2][y2];
if(find(a) != find(b)){
p[find(a)] = find(b); // 必选的边先加进来
}
}
kruskal(0, 2, 1); // 权值为1的先做
kruskal(2, 4, 2);
System.out.println(res);
}
static void kruskal(int l, int r, int c){ // 考虑每条边要不要加入到树里去
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
for(int u = l; u < r; u ++){
int x = i + dx[u], y = j + dy[u];
if(x > n || x == 0 || y == 0 || y > m) continue;
int a = g[i][j], b = g[x][y];
if(find(a) != find(b) ){
p[find(a)] = find(b);
res += c;
}
}
}
}
}
static class Pair implements Comparable<Pair>{
int a, b, c;
Pair(int a, int b, int c){
this.a = a;
this.b = b;
this.c = c;
}
public int compareTo(Pair p){
return c - p.c;
}
}
static int find(int x){
if(p[x] != x) return p[x] = find(p[x]);
return p[x];
}
}