#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int k, n;
cin >> k >> n;
int64_t ans = 0;
map<int, int64_t> L, R;
vector<int> a;
for (int i = 0; i < n; i++) {
char p, q;
int s, t;
cin >> p >> s >> q >> t;
int l = min(s, t);
int r = max(s, t);
ans += r - l;
if (p != q) {
ans++;
L[l]++;
R[r]++;
a.push_back(l);
a.push_back(r);
}
}
sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());
int m = int(a.size());
vector<int64_t> pref(m + 1);
vector<int> cntR(m + 1);
for (int i = 0; i < m; i++) {
pref[i + 1] = pref[i] + R[a[i]] * a[i];
cntR[i + 1] = cntR[i] + R[a[i]];
}
vector<int64_t> suf(m + 1);
vector<int> cntL(m + 1);
for (int i = m - 1; i >= 0; i--) {
suf[i] = suf[i + 1] + L[a[i]] * a[i];
cntL[i] = cntL[i + 1] + L[a[i]];
}
//cout << "ans: " << ans << '\n';
int64_t best = LLONG_MAX;
for (int x : a) {
int64_t res = ans;
int j = upper_bound(a.begin(), a.end(), x) - a.begin();
//cout << "j: " << j << ' ' << "suf[j]: " << suf[j] << ' ' << "cntL[j]: " << cntL[j] << '\n';
//cout << "j: " << j << ' ' << "pref[j]: " << pref[j] << ' ' << "cntR[j]: " << cntR[j] << '\n';
res += int64_t(suf[j] - int64_t(cntL[j]) * x) * 2;
res += int64_t(int64_t(cntR[j]) * x - pref[j]) * 2;
best = min(best, res);
//cout << "x: " << x << ' ' << "res: " << res << '\n';
}
if (a.empty()) {
best = ans;
}
cout << best << '\n';
return 0;
}