#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ff first
#define ss second
#define pi pair<int,int>
signed main(){
cin.tie(0)->sync_with_stdio(0);
int k, n; cin >> k >> n;
vector<int> c;
vector<pair<char,int>> x,y;
for(int i=0; i < n; i ++){
char a,b; int a1, b1; cin >> a >> a1 >> b >> b1;
c.pb(a1);c.pb(b1);
x.pb({a,a1});
y.pb({b,b1});
}
sort(c.begin(),c.end());
int xx = c[n];
int s = 0;
for(int i=0; i < n; i ++){
if(x[i].ff == y[i].ff) s += abs(y[i].ss - x[i].ss);
else s += abs(y[i].ss - xx) + abs(x[i].ss - xx) + 1;
}
xx = c[n-1];
int ss = 0;
for(int i=0; i < n; i ++){
if(x[i].ff == y[i].ff) ss += abs(y[i].ss - x[i].ss);
else ss += abs(y[i].ss - xx) + abs(x[i].ss - xx) + 1;
}
cout << min(s,ss);
}