import java.util.*

class User(val id:Int){
    private val mWait:Stack<Data> = Stack()
    fun waitingData():Iterable<Data> = mWait
    fun waitData(data:Data):Unit {
        mWait.push(data)
    }
}
class Data{
    private var mLocked:User? = null
    fun lockedUser():Iterable<User> = listOf(mLocked).filterNotNull()
    fun lockedByUser(user:User):Unit{
        mLocked = user
    }
}
fun depthFirst(user:User, depth:Int = 0):Boolean {
    if (depth > 100) return true
    return user.waitingData().flatMap(Data::lockedUser).any{depthFirst(it, depth + 1)}
}
fun occurDeadLock(users:Iterable<User>):Boolean {
    return users.any{depthFirst(it)}
}
fun main(args:Array<String>):Unit {
    val users = Array(100){User(it + 1)}
    val data = Array(100){Data()}
    for (i in 0 until readLine()!!.toInt()){
        val (u, q, d) = readLine()!!.split(' ')
        when(q){
            "lock" -> data[d.toInt() - 1].lockedByUser(users[u.toInt() - 1])
            else -> users[u.toInt() - 1].waitData(data[d.toInt() - 1])
        }
    }
    println(when{
        occurDeadLock(users.asIterable()) -> 1
        else -> 0
    })
}
