#include <bits/stdc++.h>
using namespace std;
const int N = 111111;
pair<char, string> ev[N];
int n;
int solve(char le) {
  set<char> st;
  for (int i = ('a'); i <= ('z'); i++) {
    st.insert(i);
  }
  int need = 0, has = 0;
  bool found = false;
  for (int i = (1); i <= (n); i++) {
    if (ev[i].first == '.') {
      for (auto c : ev[i].second) {
        st.erase(c);
      }
    } else if (ev[i].first == '!') {
      has++;
      set<char> keep;
      for (auto c : ev[i].second) {
        keep.insert(c);
      }
      for (int c = ('a'); c <= ('z'); c++) {
        if (keep.find(c) == keep.end()) {
          st.erase(c);
        }
      }
    } else if (i != n && ev[i].first == '?') {
      char gu = ev[i].second[0];
      if (gu == le) {
        return -1;
      } else {
        st.erase(gu);
      }
      has++;
    } else if (!found && i == n && ev[i].first == '?') {
      return 0;
    }
    if (st.find(le) == st.end()) return -1;
    if (!found && (int)(st).size() == 1 && *(st.begin()) == le) {
      found = true;
      need = has;
    }
  }
  if (!found) return -1;
  return has - need;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = (1); i <= (n); i++) {
    cin >> ev[i].first >> ev[i].second;
  }
  int ans = -1;
  for (int c = ('a'); c <= ('z'); c++) {
    ans = max(ans, solve(c));
  }
  cout << ans << "\n";
  return 0;
}
