N = gets.chomp.to_i
Planes = {}
Planes["U"] = []
Planes["D"] = []
Planes["R"] = []
Planes["L"] = []
N.times{
  x, y, u = gets.chomp.split
  Planes[u].push [x.to_i, y.to_i]
}

collision = nil

Planes["U"].each{ |a|
  Planes["D"].each{ |b|
    if a[1] < b[1] && a[0] == b[0]
      distance = (b[1] - a[1]) / 2 * 10
      unless collision.nil?
        if collision > distance
          collision = distance
        end
      else
        collision = distance
      end
    end
  }
}

Planes["R"].each{ |a|
  Planes["L"].each{ |b|
    if a[0] < b[0] && a[1] == b[1]
      distance = (b[0] - a[0]) / 2 * 10
      unless collision.nil?
        if collision > distance
          collision = distance
        end
      else
        collision = distance
      end
    end
  }
}

Planes["U"].each{ |a|
  Planes["R"].each{ |b|
    if a[0] > b[0] && a[1] < b[1] && (a[0] - b[0]) == (b[1] - a[1])
      distance = (a[0] - b[0]) * 10
      unless collision.nil?
        if collision > distance
          collision = distance
        end
      else
        collision = distance
      end
    end
  }
}

Planes["U"].each{ |a|
  Planes["L"].each{ |b|
    if a[0] < b[0] && a[1] < b[1] && (b[0] - a[0]) == (b[1] - a[1])
      distance = (b[0] - a[0]) * 10
      unless collision.nil?
        if collision > distance
          collision = distance
        end
      else
        collision = distance
      end
    end
  }
}

Planes["D"].each{ |a|
  Planes["R"].each{ |b|
    if a[0] > b[0] && a[1] > b[1] && (a[0] - b[0]) == (a[1] - b[1])
      distance = (a[0] - b[0]) * 10
      unless collision.nil?
        if collision > distance
          collision = distance
        end
      else
        collision = distance
      end
    end
  }
}

Planes["D"].each{ |a|
  Planes["L"].each{ |b|
    if a[0] < b[0] && a[1] > b[1] && (b[0] - a[0]) == (a[1] - b[1])
      distance = (b[0] - a[0]) * 10
      unless collision.nil?
        if collision > distance
          collision = distance
        end
      else
        collision = distance
      end
    end
  }
}

if collision.nil?
  puts "SAFE"
else
  puts collision
end
