#include using namespace std; // the tuple (type, fit) has to be unique in the input #define all(x) begin(x), end(x) #define sz(x) (ll)(x).size() using ll = long long; using ld = long double; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ll n; cin >> n; ll socks = 0; map count; for (ll i = 0; i < n; i++) { string a, b; ll c; cin >> a >> b >> c; socks += c; if (b == "any") c = 1; count[a] = max(count[a], c); } ll res = 1; for (auto e : count) res += e.second; if (res > socks) { cout << "impossible" << endl; } else { cout << res << endl; } }