#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
int a[100100][2][2];
int dis(int p[2], int q[2]) { return abs(p[0] - q[0]) + abs(p[1] - q[1]); }
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
        scanf("%d%d%d%d", &a[i][0][0], &a[i][0][1], &a[i][1][0], &a[i][1][1]);
    long long ans = dis(a[n - 1][0], a[n - 1][1]);
    for (int i = 1; i < n; i++)
        ans += min(dis(a[i - 1][0], a[i][0]) + dis(a[i - 1][1], a[i][1]),
                   dis(a[i - 1][0], a[i][1]) + dis(a[i - 1][1], a[i][0]));
    printf("%lld", ans);
    return 0;
}
