/*
Telebe of Adicto && Mamedov yani AzeTurk810
I see humans but no humanity
*/
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <istream>
#include <utility>
#include <vector>
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
using namespace std;
#define ln '\n'
#define INFi 1e9
#define INFll 1e18
#ifdef ONPC
#include <algo.hpp>
#else
#define dbg(...)
#define dbg_out(...)
#define myassert(Expr, Msg) ;
#endif
struct node {
struct point {
int x, y;
};
point st, fs;
};
inline std::ostream &operator<<(std::ostream &os, const node &n) {
return os << "[St: (" << n.st.x << ", " << n.st.y << ") -> Fs: (" << n.fs.x << ", " << n.fs.y << ")]" << ln;
}
int _n, _k;
vector<node> V;
ll ans = INFll, sum = 0;
inline void systemd() {
sum = 0;
V.resize(_n);
}
ll calc(ll x) {
ll res = 0;
for (size_t i = 0; i < _n; i++) {
if (V[i].st.x == V[i].fs.x) {
res += abs(V[i].st.y - V[i].fs.y);
continue;
}
res += abs(V[i].st.y - x) + abs(V[i].fs.y - x) + 1;
}
return res;
}
void ternary_search() {
ans = INFll;
ll l = 0, r = INFi;
while (r - l > 2) {
int sz = (r - l) / 3;
ll m1 = l + sz, m2 = r - sz;
ll al = calc(m1);
ll ar = calc(m2);
if (al < ar) {
r = m1 - 1;
} else if (al > ar) {
l = m2 + 1;
} else {
break;
}
}
for (ll i = l; i <= r; i++) {
ans = min(ans, calc(i));
}
}
char solve() {
if (!(cin >> _k >> _n))
return 1;
systemd();
vector<ll> P;
for (size_t i = 0; i < _n; i++) {
char temp1, temp2;
int j1, j2;
cin >> temp1 >> j1 >> temp2 >> j2;
temp2 -= 'A';
temp1 -= 'A';
V[i].fs.x = temp2;
V[i].st.x = temp1;
V[i].fs.y = j2;
V[i].st.y = j1;
if (temp1 != temp2) {
sum++;
P.push_back(j1);
P.push_back(j2);
} else {
sum += abs(j1 - j2);
}
}
sort(V.begin(), V.end(), [&](const node &l, const node &r) {
return (l.fs.y - l.st.y) < (r.fs.y - r.st.y);
});
sort(P.begin(), P.end());
if (P.empty()) {
cout << sum << ln;
return 0;
}
int m = P.size() / 2;
ll p = P[m];
ans = 0;
for (const ll &i : P) {
ans += abs(i - p);
}
cout << ans + sum << ln;
return 0;
}
// Attack on titan<3
signed main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
int t = 1e9;
// cin >> t;
for (int cases = 0; cases < t; cases++) {
if (solve())
break;
#ifdef ONPC
cerr << "__________\n";
#endif
}
}
// Just Imaginary
/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⠀⠀⠀⢀⣴⣾⠀⠀⠀⡀⢀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣦⣾⣿⣿⣿⣿⣿⡆⠁⠀⢀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⡿⠁⠀⡠⠂⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠠⠔⠚⣿⣿⣿⣿⣿⣦⡄⠀⠁⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢀⠠⠐⢂⠉⡀⣀⣤⣄⢻⣿⣿⡟⢈⡹⣿⡀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⡀⠄⠂⠈⠀⣶⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠘⣷⡀⠀⡀⠐⠂⠐⢄
⠀⠀⠀⠀⠀⠀⠀⣿⣿⠟⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⣀⣾⣷⠯⠀⠤⠤⠄⠈
⠀⠀⠀⠀⠀⠀⣼⣿⡟⠀⠀⣹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⡀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣰⣿⠋⠀⠀⢠⣾⣿⣿⣿⣿⣿⣭⠟⢻⣿⣿⣿⣿⡿⠁⠀⠀⠀⠀
⠀⠀⠀⣀⣶⡟⠁⠀⢾⣶⣿⠟⠉⠈⢻⣿⣿⣿⣦⣜⠀⠛⠛⠿⠁⠀⠀⠀⠀⠀
⠚⠻⠿⠿⡿⠁⠀⢠⣿⣿⠁⠀⣠⠖⠋⠉⠻⣿⣿⣿⣶⡀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣰⣿⡿⠃⠠⠊⠁⠀⠀⠀⠀⠈⢿⣿⣿⠟⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⣴⡿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⣠⣾⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⢀⣴⠾⠟⠛⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
*/