#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  int n, m;
  cin >> n >> m;
  int right = 0, left = n + 1;
  for (int i = 0; i < m; i++) {
    t.clear();
    s.clear();
    for (int j = 0; j < 4; j++) {
      cin >> t;
      s += t;
    }
    int k;
    cin >> k;
    if (s.size() == 11) {
      if (k < left) left = k;
    } else if (k > right)
      right = k;
    if (right >= left - 1) {
      cout << -1;
      return 0;
    }
  }
  cout << left - right - 1;
  return 0;
}
