import Foundation
let main: () = {
    let (N, K) = *listOfInt()
    let A = listOfInt(-1)
    var O = IntArray(N) { -1 }
    var S = [Int]()
    var v = 0
    while O[v] == -1 {
        O[v] = S.count
        S.append(v)
        v = A[v]
    }
    let c = S.count - O[v]
    let l = O[v]
    let index = K < l ? K : l + (K - l) % c
    print(S[index] + 1)
}()

//----------------------------------

let dx = [1, 0, -1, 0] //[1, 0, -1, 0, -1,  1, -1, 1]
let dy = [0, 1, 0, -1] //[0, 1, 0, -1, -1, -1,  1, 1]

@inlinable func gcd(_ a: Int, _ b: Int) -> Int { (b > 0) ? gcd(b, a % b) : a }
@inlinable func lcm(_ a: Int, _ b: Int) -> Int { a / gcd(a, b) * b }

//----------------------------------

infix operator  =~ : ComparisonPrecedence
infix operator !=~ : ComparisonPrecedence
func =~ <T: FixedWidthInteger>(left: T, right: Range<T>) -> Bool { right ~= left }
func !=~ <T: FixedWidthInteger>(left: T, right: Range<T>) -> Bool { !(right ~= left) }
func =~ <T: FixedWidthInteger>(left: T, right: ClosedRange<T>) -> Bool { right ~= left }
func !=~ <T: FixedWidthInteger>(left: T, right: ClosedRange<T>) -> Bool { !(right ~= left) }

func =~ <T: Collection > (left: T.Element, right: T) -> Bool where T.Element : Equatable { right.contains(left) }
func !=~ <T: Collection > (left: T.Element, right: T) -> Bool where T.Element : Equatable { !right.contains(left) }

infix operator /^ : MultiplicationPrecedence
infix operator /^= : AssignmentPrecedence
func /^ <T: FixedWidthInteger>(left: T, right: T) -> T { (left + (right - 1)) / right }
func /^= <T: FixedWidthInteger>(left: inout T, right: T) { left = (left + (right - 1)) / right }

@inlinable func chmax<T: Comparable>(_ m: inout T, _ q: T) { if (m < q) { m = q } }
@inlinable func chmin<T: Comparable>(_ m: inout T, _ q: T) { if (m > q) { m = q } }
@inlinable func chRmax<T: Comparable>(_ m: inout T, _ q: T) -> Bool { if (m < q) { m = q; return true } else { return false } }
@inlinable func chRmin<T: Comparable>(_ m: inout T, _ q: T) -> Bool { if (m > q) { m = q; return true } else { return false } }

prefix operator *
prefix func * <T> (a: [T]) -> (T, T) { (a[0], a[1]) }
prefix func * <T> (a: [T]) -> (T, T, T) { (a[0], a[1], a[2]) }
prefix func * <T> (a: [T]) -> (T, T, T, T) { (a[0], a[1], a[2], a[3]) }
prefix func * <T> (a: [T]) -> (T, T, T, T, T) { (a[0], a[1], a[2], a[3], a[4]) }
prefix func * <T> (a: [T]) -> (T, T, T, T, T, T) { (a[0], a[1], a[2], a[3], a[4], a[5]) }

func printErr(_ str: String, terminator: String = "\n") {
    let s = str + terminator
    FileHandle.standardError.write(s.data(using: .utf8)!)
    FileHandle.standardError.synchronizeFile()
}

@inlinable func next() -> String { readLine()! }
@inlinable func nextInt() -> Int { Int(next())! }
@inlinable func nextDouble() -> Double { Double(next())! }
@inlinable func listOfString() -> [String] { next().split(separator: " ").map(String.init) }
@inlinable func listOfInt() -> [Int] { listOfString().map { Int($0)! } }
@inlinable func listOfInt(_ offset: Int = 0) -> [Int] { listOfString().map { Int($0)! + offset } }
@inlinable func listOfInt(_ offsets: Int ...) -> [Int] { listOfString().enumerated().map { Int($0.element)! + offsets[$0.offset % offsets.count] } }
@inlinable func listOfDouble(_ offset: Double = 0.0) -> [Double] { listOfString().map { Double($0)! + offset } }
@inlinable func listOfDouble(_ offsets: Double ...) -> [Double] { listOfString().enumerated().map { Double($0.element)! + offsets[$0.offset % offsets.count] } }

extension Int {
    init(s: String) { self.init(s)! }
    var isEven: Bool { self.isMultiple(of: 2) }
    var isOdd: Bool { !self.isEven }
    var isTrue: Bool { self != 0 }
    var isFalse: Bool { !self.isTrue }
    var toString: String { String(self) }
    var toChar: Character { Character(UnicodeScalar(UInt8(self))) }
}
func + (left: Int, right: Bool) -> Int { left + (right ? 1 : 0) }
extension Character {
    var asciiCode: Int { Int(self.asciiValue!) }
    var string: String { String(self) }
}
extension String {
    @inlinable subscript (position: Int) -> Character { self[self.index(self.startIndex, offsetBy: position)] }
    @inlinable func repeate(_ times: Int) -> String { String(repeating: self, count: times) }
    //  @inlinable subscript (n: Int) -> String { String(self[self.index(self.startIndex, offsetBy: n)]) }
    //  @inlinable subscript (n: Int) -> Int { Int(self[self.index(self.startIndex, offsetBy: n)].asciiValue!) }
    var toInt: Int { Int(self)! }
}
extension String { // VB like
    @inlinable func _index(_ position: Int) -> String.Index! {
        if !(0 ..< self.count ~= position) { return nil }
        return self.index(self.startIndex, offsetBy: position)
    }
    @inlinable func mid(from index: Int, length: Int) -> String! {
        if let startPosition = self._index(index) {
            if let endPosition = self._index(index + length - 1) {
                return String(self[startPosition...endPosition])
            } else {
                let endPosition = self.index(before: self.endIndex)
                return String(self[startPosition...endPosition])
            }
        }
        return ""
    }
    @inlinable func left(_ length: Int) -> String { String(self.prefix(length)) }
    @inlinable func right(_ length: Int) -> String { String(self.suffix(length)) }
}

extension Dictionary {
    @inlinable mutating func getOrSet(_ key: Key, _ defaultValue: () -> Value) -> Value {
        if let stored = self[key] { return stored }
        else {
            let newValue = defaultValue()
            self[key] = newValue
            return newValue
        }
    }
    @inlinable mutating func getOrElse(_ key: Key, _ defaultValue: () -> Value) -> Value {
        if let stored = self[key] { return stored } else { return defaultValue() }
    }
    @inlinable func containsKey(_ key: Key) -> Bool { self.keys.contains(key) }
}

extension Set {
    static func += (left: inout Set<Element>, right: Element) { left.insert(right) }
    static func -= (left: inout Set<Element>, right: Element) { left.remove(right) }
}

extension Array {
    static func += (left: inout Array<Element>, right: Element) { left.append(right) }
    init(_ size: Int, _ initValue: ((Int) -> Element)) {
        self = [Element]()
        for index in 0 ..< size {
            let value = initValue(index)
            self.append(value)
        }
    }
    init(_ size: Int, _ initValue: (() -> Element)) {
        self = [Element]()
        for _ in 0 ..< size {
            let value = initValue()
            self.append(value)
        }
    }
}
typealias IntArray = Array<Int>
typealias DoubleArray = Array<Double>
typealias BoolArray = Array<Bool>
typealias StringArray = Array<String>

extension Array where Element == Int {
    init(_ size: Int) {
        self = [Element](repeating: 0, count: size)
    }
}
extension Array where Element == Double {
    init(_ size: Int) {
        self = [Element](repeating: 0.0, count: size)
    }
}
extension Array where Element == Bool {
    init(_ size: Int) {
        self = [Element](repeating: false, count: size)
    }
}
extension Array where Element == String {
    init(_ size: Int) {
        self = [Element](repeating: "", count: size)
    }
}

extension Array {
    @inlinable func count(_ predicate: ((Element) -> Bool)) -> Int {
        var cnt = 0; for e in self { if (predicate(e)) { cnt += 1 } }
        return cnt
    }
    @inlinable func groupBy<K>(_ keySelector: (Element) -> K) -> [K : [Element]] {
        var destination = [K : [Element]]()
        for element in self {
            let key = keySelector(element)
            var list = destination.getOrSet(key) { [Element]() }
            list.append(element)
            destination[key] = list
        }
        return destination
    }
    @inlinable func groupByIndexed<K>(_ keySelector: (Element) -> K) -> [K : [Int]] {
        var destination = [K : [Int]]()
        for element in self.enumerated() {
            let key = keySelector(element.element)
            var list = destination.getOrSet(key) { [Int]() }
            list.append(element.offset)
            destination[key] = list
        }
        return destination
    }
}

extension Array {
    func binarySearch(_ element: Element, by compare: (Element, Element) -> Int, fromIndex: Int = 0, toIndex: Int = -1) -> Int {
        var low = fromIndex
        var high = (toIndex == -1) ? self.count - 1 : toIndex - 1
        while (low <= high) {
            let mid = (low + high) >> 1 // safe from overflows
            let midVal = self[mid]
            let cmp = compare(midVal, element)
            if (cmp < 0) { low = mid + 1 }          //-1
            else if (0 < cmp) { high = mid - 1 }    // 1
            else { return mid } // key found        // 0
        }
        return -(low + 1)  // key not found
    }
}
extension Array where Element : Comparable {
    func binarySearch(_ element: Element, fromIndex: Int = 0, toIndex: Int = -1) -> Int {
        var low = fromIndex
        var high = (toIndex == -1) ? self.count - 1 : toIndex - 1
        while (low <= high) {
            let mid = (low + high) >> 1 // safe from overflows
            let midVal = self[mid]
            if (midVal < element) { low = mid + 1 }
            else if (midVal > element) { high = mid - 1 }
            else { return mid } // key found
        }
        return -(low + 1)  // key not found
    }
}

extension Array where Element == Int {
    @inlinable func distinct() -> [Element] {
        var set = Set<Element>(), ary = [Element]()
        for n in self.indices { if !set.contains(self[n]) { ary.append(self[n]); set.insert(self[n]) } }
        return ary
    }
    @inlinable func any(_ predicate: (Element) -> Bool) -> Bool {
        var any = false; for element in self { if predicate(element) { any = true } }
        return any
    }
    @inlinable func all(_ predicate: (Element) -> Bool) -> Bool {
        self.allSatisfy(predicate)
    }
    @inlinable func sum() -> Element { self.reduce(0, +) }
    @inlinable func sum(by predicate: (Element) -> Element) -> Element {
        var sum = 0; for e in self { sum += predicate(e) }
        return sum
    }
    @inlinable func joinToString(_ sepatator: String = " ") -> String { self.map { String($0) }.joined(separator: sepatator) }
}

extension Array where Element == Double {
    @inlinable func sum() -> Element { self.reduce(0.0, +) }
    @inlinable func sum(by predicate: (Element) -> Element) -> Element {
        var sum = 0.0; for e in self { sum += predicate(e) }
        return sum
    }
    @inlinable func joinToString(_ sepatator: String = " ") -> String { self.map { String($0) }.joined(separator: sepatator) }
}
extension Array where Element == String {
    @inlinable func toIntDouble() -> (Int, Double) { (Int(self[0])!, Double(self[1])!) }
    @inlinable func toIntString() -> (Int, String) { (Int(self[0])!, self[1]) }
    @inlinable func toIntIntString() -> (Int, Int, String) { (Int(self[0])!, Int(self[1])!, self[2]) }
}

@inlinable func repeate(_ times1: Int, _ action: () -> Void) {
    for _ in 0 ..< times1 { action() }
}
@inlinable func repeate(_ times1: Int, _ action: (Int) -> Void) {
    for index1 in 0 ..< times1 {
        action(index1)
    }
}
@inlinable func repeate(_ times1: Int, _ times2: Int, _ action: (Int, Int) -> Void) {
    for index1 in 0 ..< times1 {
        for index2 in 0 ..< times2 {
            action(index1, index2)
        }
    }
}
@inlinable func repeate(_ times1: Int, _ times2: Int, _ times3: Int, _ action: (Int, Int, Int) -> Void) {
    for index1 in 0 ..< times1 {
        for index2 in 0 ..< times2 {
            for index3 in 0 ..< times3 {
                action(index1, index2, index3)
            }
        }
    }
}
@inlinable func repeate(_ times1: Int, _ times2: Int, _ times3: Int, _ times4: Int, _ action: (Int, Int, Int, Int) -> Void) {
    for index1 in 0 ..< times1 {
        for index2 in 0 ..< times2 {
            for index3 in 0 ..< times3 {
                for index4 in 0 ..< times4 {
                    action(index1, index2, index3, index4)
                }
            }
        }
    }
}

func measureTimeSeconds(block: (() -> Void)) -> Double {
    let startTime = Date()
    block()
    let duration = -startTime.timeIntervalSinceNow
    return duration
}

extension Array {
    func permutation (_ length: Int) -> [[Element]] {
        if length < 0 || length > self.count {
            return []
        } else if length == 0 {
            return [[]]
        } else {
            var permutations: [[Element]] = []
            let combinations = combination(length)
            for combination in combinations {
                var endArray: [[Element]] = []
                var mutableCombination = combination
                permutations += self.permutationHelper(length, array: &mutableCombination, endArray: &endArray)
            }
            return permutations
        }
    }
    private func permutationHelper(_ n: Int, array: inout [Element], endArray: inout [[Element]]) -> [[Element]] {
        if n == 1 {
            endArray += [array]
        }
        for i in 0  ..< n {
            _ = permutationHelper(n - 1, array: &array, endArray: &endArray)
            let j = n % 2 == 0 ? i : 0
            let temp: Element = array[j]
            array[j] = array[n - 1]
            array[n - 1] = temp
        }
        return endArray
    }
    /**
     - parameter length:
     - returns: Returns all of the combinations in the array of the given length
     */
    func combination (_ length: Int) -> [[Element]] {
        if length < 0 || length > self.count {
            return []
        }
        var indexes: [Int] = (0..<length).reduce([]) {$0 + [$1]}
        var combinations: [[Element]] = []
        let offset = self.count - indexes.count
        while true {
            var combination: [Element] = []
            for index in indexes {
                combination.append(self[index])
            }
            combinations.append(combination)
            var i = indexes.count - 1
            while i >= 0 && indexes[i] == i + offset {
                i -= 1
            }
            if i < 0 {
                break
            }
            i += 1
            let start = indexes[i-1] + 1
            for j in (i-1)..<indexes.count {
                indexes[j] = start + j - i + 1
            }
        }
        return combinations
    }
    /**
     - parameter length: The length of each permutations
     - returns: All of the permutations of this array of a given length, allowing repeats
     */
    func repeatedPermutation(_ length: Int) -> [[Element]] {
        if length < 1 {
            return []
        }
        var indexes: [[Int]] = []
        indexes.repeatedPermutationHelper([], length: length, arrayLength: self.count, indexes: &indexes)
        return indexes.map({ $0.map({ i in self[i] }) })
    }
    private func repeatedPermutationHelper(_ seed: [Int], length: Int, arrayLength: Int, indexes: inout [[Int]]) {
        if seed.count == length {
            indexes.append(seed)
            return
        }
        for i in (0..<arrayLength) {
            var newSeed: [Int] = seed
            newSeed.append(i)
            self.repeatedPermutationHelper(newSeed, length: length, arrayLength: arrayLength, indexes: &indexes)
        }
    }
}


import Foundation
let main: () = {

    let (N, K) = *listOfInt()
    let A = listOfInt(-1)
    var ans = 0
    if K < N {
        repeate(K) {
            ans = A[ans]
        }
        return print(ans + 1)
    }
    var M = [Int: Int]()
    var V = [Int]()
    for n in 0 ..< N {
        if M[ans] != nil { break }
        M[ans] = n
        V.append(ans)
        ans = A[ans]
    }
    let p = M[ans]!
    let res = M.count - p
    let index = p + ((K - p) % res)
    ans = V[index]

    print(ans + 1)

}()

//----------------------------------

let dx = [1, 0, -1, 0] //[1, 0, -1, 0, -1,  1, -1, 1]
let dy = [0, 1, 0, -1] //[0, 1, 0, -1, -1, -1,  1, 1]

@inlinable func gcd(_ a: Int, _ b: Int) -> Int { (b > 0) ? gcd(b, a % b) : a }
@inlinable func lcm(_ a: Int, _ b: Int) -> Int { a / gcd(a, b) * b }

//----------------------------------

infix operator  =~ : ComparisonPrecedence
infix operator !=~ : ComparisonPrecedence
func =~ <T: FixedWidthInteger>(left: T, right: Range<T>) -> Bool { right ~= left }
func !=~ <T: FixedWidthInteger>(left: T, right: Range<T>) -> Bool { !(right ~= left) }
func =~ <T: FixedWidthInteger>(left: T, right: ClosedRange<T>) -> Bool { right ~= left }
func !=~ <T: FixedWidthInteger>(left: T, right: ClosedRange<T>) -> Bool { !(right ~= left) }

func =~ <T: Collection > (left: T.Element, right: T) -> Bool where T.Element : Equatable { right.contains(left) }
func !=~ <T: Collection > (left: T.Element, right: T) -> Bool where T.Element : Equatable { !right.contains(left) }

infix operator /^ : MultiplicationPrecedence
infix operator /^= : AssignmentPrecedence
func /^ <T: FixedWidthInteger>(left: T, right: T) -> T { (left + (right - 1)) / right }
func /^= <T: FixedWidthInteger>(left: inout T, right: T) { left = (left + (right - 1)) / right }

@inlinable func chmax<T: Comparable>(_ m: inout T, _ q: T) { if (m < q) { m = q } }
@inlinable func chmin<T: Comparable>(_ m: inout T, _ q: T) { if (m > q) { m = q } }
@inlinable func chRmax<T: Comparable>(_ m: inout T, _ q: T) -> Bool { if (m < q) { m = q; return true } else { return false } }
@inlinable func chRmin<T: Comparable>(_ m: inout T, _ q: T) -> Bool { if (m > q) { m = q; return true } else { return false } }

prefix operator *
prefix func * <T> (a: [T]) -> (T, T) { (a[0], a[1]) }
prefix func * <T> (a: [T]) -> (T, T, T) { (a[0], a[1], a[2]) }
prefix func * <T> (a: [T]) -> (T, T, T, T) { (a[0], a[1], a[2], a[3]) }
prefix func * <T> (a: [T]) -> (T, T, T, T, T) { (a[0], a[1], a[2], a[3], a[4]) }
prefix func * <T> (a: [T]) -> (T, T, T, T, T, T) { (a[0], a[1], a[2], a[3], a[4], a[5]) }

func printErr(_ str: String, terminator: String = "\n") {
    let s = str + terminator
    FileHandle.standardError.write(s.data(using: .utf8)!)
    FileHandle.standardError.synchronizeFile()
}

@inlinable func next() -> String { readLine()! }
@inlinable func nextInt() -> Int { Int(next())! }
@inlinable func nextDouble() -> Double { Double(next())! }
@inlinable func listOfString() -> [String] { next().split(separator: " ").map(String.init) }
@inlinable func listOfInt() -> [Int] { listOfString().map { Int($0)! } }
@inlinable func listOfInt(_ offset: Int = 0) -> [Int] { listOfString().map { Int($0)! + offset } }
@inlinable func listOfInt(_ offsets: Int ...) -> [Int] { listOfString().enumerated().map { Int($0.element)! + offsets[$0.offset % offsets.count] } }
@inlinable func listOfDouble(_ offset: Double = 0.0) -> [Double] { listOfString().map { Double($0)! + offset } }
@inlinable func listOfDouble(_ offsets: Double ...) -> [Double] { listOfString().enumerated().map { Double($0.element)! + offsets[$0.offset % offsets.count] } }

extension Int {
    init(s: String) { self.init(s)! }
    var isEven: Bool { self.isMultiple(of: 2) }
    var isOdd: Bool { !self.isEven }
    var isTrue: Bool { self != 0 }
    var isFalse: Bool { !self.isTrue }
    var toString: String { String(self) }
    var toChar: Character { Character(UnicodeScalar(UInt8(self))) }
}
func + (left: Int, right: Bool) -> Int { left + (right ? 1 : 0) }
extension Character {
    var asciiCode: Int { Int(self.asciiValue!) }
    var string: String { String(self) }
}
extension String {
    @inlinable subscript (position: Int) -> Character { self[self.index(self.startIndex, offsetBy: position)] }
    @inlinable func repeate(_ times: Int) -> String { String(repeating: self, count: times) }
    //  @inlinable subscript (n: Int) -> String { String(self[self.index(self.startIndex, offsetBy: n)]) }
    //  @inlinable subscript (n: Int) -> Int { Int(self[self.index(self.startIndex, offsetBy: n)].asciiValue!) }
    var toInt: Int { Int(self)! }
}
extension String { // VB like
    @inlinable func _index(_ position: Int) -> String.Index! {
        if !(0 ..< self.count ~= position) { return nil }
        return self.index(self.startIndex, offsetBy: position)
    }
    @inlinable func mid(from index: Int, length: Int) -> String! {
        if let startPosition = self._index(index) {
            if let endPosition = self._index(index + length - 1) {
                return String(self[startPosition...endPosition])
            } else {
                let endPosition = self.index(before: self.endIndex)
                return String(self[startPosition...endPosition])
            }
        }
        return ""
    }
    @inlinable func left(_ length: Int) -> String { String(self.prefix(length)) }
    @inlinable func right(_ length: Int) -> String { String(self.suffix(length)) }
}

extension Dictionary {
    @inlinable mutating func getOrSet(_ key: Key, _ defaultValue: () -> Value) -> Value {
        if let stored = self[key] { return stored }
        else {
            let newValue = defaultValue()
            self[key] = newValue
            return newValue
        }
    }
    @inlinable mutating func getOrElse(_ key: Key, _ defaultValue: () -> Value) -> Value {
        if let stored = self[key] { return stored } else { return defaultValue() }
    }
    @inlinable func containsKey(_ key: Key) -> Bool { self.keys.contains(key) }
}

extension Set {
    static func += (left: inout Set<Element>, right: Element) { left.insert(right) }
    static func -= (left: inout Set<Element>, right: Element) { left.remove(right) }
}

extension Array {
    static func += (left: inout Array<Element>, right: Element) { left.append(right) }
    init(_ size: Int, _ initValue: ((Int) -> Element)) {
        self = [Element]()
        for index in 0 ..< size {
            let value = initValue(index)
            self.append(value)
        }
    }
    init(_ size: Int, _ initValue: (() -> Element)) {
        self = [Element]()
        for _ in 0 ..< size {
            let value = initValue()
            self.append(value)
        }
    }
}
typealias IntArray = Array<Int>
typealias DoubleArray = Array<Double>
typealias BoolArray = Array<Bool>
typealias StringArray = Array<String>

extension Array where Element == Int {
    init(_ size: Int) {
        self = [Element](repeating: 0, count: size)
    }
}
extension Array where Element == Double {
    init(_ size: Int) {
        self = [Element](repeating: 0.0, count: size)
    }
}
extension Array where Element == Bool {
    init(_ size: Int) {
        self = [Element](repeating: false, count: size)
    }
}
extension Array where Element == String {
    init(_ size: Int) {
        self = [Element](repeating: "", count: size)
    }
}

extension Array {
    @inlinable func count(_ predicate: ((Element) -> Bool)) -> Int {
        var cnt = 0; for e in self { if (predicate(e)) { cnt += 1 } }
        return cnt
    }
    @inlinable func groupBy<K>(_ keySelector: (Element) -> K) -> [K : [Element]] {
        var destination = [K : [Element]]()
        for element in self {
            let key = keySelector(element)
            var list = destination.getOrSet(key) { [Element]() }
            list.append(element)
            destination[key] = list
        }
        return destination
    }
    @inlinable func groupByIndexed<K>(_ keySelector: (Element) -> K) -> [K : [Int]] {
        var destination = [K : [Int]]()
        for element in self.enumerated() {
            let key = keySelector(element.element)
            var list = destination.getOrSet(key) { [Int]() }
            list.append(element.offset)
            destination[key] = list
        }
        return destination
    }
}

extension Array {
    func binarySearch(_ element: Element, by compare: (Element, Element) -> Int, fromIndex: Int = 0, toIndex: Int = -1) -> Int {
        var low = fromIndex
        var high = (toIndex == -1) ? self.count - 1 : toIndex - 1
        while (low <= high) {
            let mid = (low + high) >> 1 // safe from overflows
            let midVal = self[mid]
            let cmp = compare(midVal, element)
            if (cmp < 0) { low = mid + 1 }          //-1
            else if (0 < cmp) { high = mid - 1 }    // 1
            else { return mid } // key found        // 0
        }
        return -(low + 1)  // key not found
    }
}
extension Array where Element : Comparable {
    func binarySearch(_ element: Element, fromIndex: Int = 0, toIndex: Int = -1) -> Int {
        var low = fromIndex
        var high = (toIndex == -1) ? self.count - 1 : toIndex - 1
        while (low <= high) {
            let mid = (low + high) >> 1 // safe from overflows
            let midVal = self[mid]
            if (midVal < element) { low = mid + 1 }
            else if (midVal > element) { high = mid - 1 }
            else { return mid } // key found
        }
        return -(low + 1)  // key not found
    }
}

extension Array where Element == Int {
    @inlinable func distinct() -> [Element] {
        var set = Set<Element>(), ary = [Element]()
        for n in self.indices { if !set.contains(self[n]) { ary.append(self[n]); set.insert(self[n]) } }
        return ary
    }
    @inlinable func any(_ predicate: (Element) -> Bool) -> Bool {
        var any = false; for element in self { if predicate(element) { any = true } }
        return any
    }
    @inlinable func all(_ predicate: (Element) -> Bool) -> Bool {
        self.allSatisfy(predicate)
    }
    @inlinable func sum() -> Element { self.reduce(0, +) }
    @inlinable func sum(by predicate: (Element) -> Element) -> Element {
        var sum = 0; for e in self { sum += predicate(e) }
        return sum
    }
    @inlinable func joinToString(_ sepatator: String = " ") -> String { self.map { String($0) }.joined(separator: sepatator) }
}

extension Array where Element == Double {
    @inlinable func sum() -> Element { self.reduce(0.0, +) }
    @inlinable func sum(by predicate: (Element) -> Element) -> Element {
        var sum = 0.0; for e in self { sum += predicate(e) }
        return sum
    }
    @inlinable func joinToString(_ sepatator: String = " ") -> String { self.map { String($0) }.joined(separator: sepatator) }
}
extension Array where Element == String {
    @inlinable func toIntDouble() -> (Int, Double) { (Int(self[0])!, Double(self[1])!) }
    @inlinable func toIntString() -> (Int, String) { (Int(self[0])!, self[1]) }
    @inlinable func toIntIntString() -> (Int, Int, String) { (Int(self[0])!, Int(self[1])!, self[2]) }
}

@inlinable func repeate(_ times1: Int, _ action: () -> Void) {
    for _ in 0 ..< times1 { action() }
}
@inlinable func repeate(_ times1: Int, _ action: (Int) -> Void) {
    for index1 in 0 ..< times1 {
        action(index1)
    }
}
@inlinable func repeate(_ times1: Int, _ times2: Int, _ action: (Int, Int) -> Void) {
    for index1 in 0 ..< times1 {
        for index2 in 0 ..< times2 {
            action(index1, index2)
        }
    }
}
@inlinable func repeate(_ times1: Int, _ times2: Int, _ times3: Int, _ action: (Int, Int, Int) -> Void) {
    for index1 in 0 ..< times1 {
        for index2 in 0 ..< times2 {
            for index3 in 0 ..< times3 {
                action(index1, index2, index3)
            }
        }
    }
}
@inlinable func repeate(_ times1: Int, _ times2: Int, _ times3: Int, _ times4: Int, _ action: (Int, Int, Int, Int) -> Void) {
    for index1 in 0 ..< times1 {
        for index2 in 0 ..< times2 {
            for index3 in 0 ..< times3 {
                for index4 in 0 ..< times4 {
                    action(index1, index2, index3, index4)
                }
            }
        }
    }
}

func measureTimeSeconds(block: (() -> Void)) -> Double {
    let startTime = Date()
    block()
    let duration = -startTime.timeIntervalSinceNow
    return duration
}

extension Array {
    func permutation (_ length: Int) -> [[Element]] {
        if length < 0 || length > self.count {
            return []
        } else if length == 0 {
            return [[]]
        } else {
            var permutations: [[Element]] = []
            let combinations = combination(length)
            for combination in combinations {
                var endArray: [[Element]] = []
                var mutableCombination = combination
                permutations += self.permutationHelper(length, array: &mutableCombination, endArray: &endArray)
            }
            return permutations
        }
    }
    private func permutationHelper(_ n: Int, array: inout [Element], endArray: inout [[Element]]) -> [[Element]] {
        if n == 1 {
            endArray += [array]
        }
        for i in 0  ..< n {
            _ = permutationHelper(n - 1, array: &array, endArray: &endArray)
            let j = n % 2 == 0 ? i : 0
            let temp: Element = array[j]
            array[j] = array[n - 1]
            array[n - 1] = temp
        }
        return endArray
    }
    /**
     - parameter length:
     - returns: Returns all of the combinations in the array of the given length
     */
    func combination (_ length: Int) -> [[Element]] {
        if length < 0 || length > self.count {
            return []
        }
        var indexes: [Int] = (0..<length).reduce([]) {$0 + [$1]}
        var combinations: [[Element]] = []
        let offset = self.count - indexes.count
        while true {
            var combination: [Element] = []
            for index in indexes {
                combination.append(self[index])
            }
            combinations.append(combination)
            var i = indexes.count - 1
            while i >= 0 && indexes[i] == i + offset {
                i -= 1
            }
            if i < 0 {
                break
            }
            i += 1
            let start = indexes[i-1] + 1
            for j in (i-1)..<indexes.count {
                indexes[j] = start + j - i + 1
            }
        }
        return combinations
    }
    /**
     - parameter length: The length of each permutations
     - returns: All of the permutations of this array of a given length, allowing repeats
     */
    func repeatedPermutation(_ length: Int) -> [[Element]] {
        if length < 1 {
            return []
        }
        var indexes: [[Int]] = []
        indexes.repeatedPermutationHelper([], length: length, arrayLength: self.count, indexes: &indexes)
        return indexes.map({ $0.map({ i in self[i] }) })
    }
    private func repeatedPermutationHelper(_ seed: [Int], length: Int, arrayLength: Int, indexes: inout [[Int]]) {
        if seed.count == length {
            indexes.append(seed)
            return
        }
        for i in (0..<arrayLength) {
            var newSeed: [Int] = seed
            newSeed.append(i)
            self.repeatedPermutationHelper(newSeed, length: length, arrayLength: arrayLength, indexes: &indexes)
        }
    }
}


func readTwoInts(separator: String.Element = " ") -> (a: Int, b: Int) {
    let ints = readLine()!.split(separator: separator).map { Int($0)! }
    return (a: ints[0], b: ints[1])
}

func readInts(separator: String.Element = " ") -> [Int] {
    return readLine()!.split(separator: separator).map { Int($0)! }
}

func mainD() {
    let (N, K) = readTwoInts()
    let telepoter = readInts()

    var position = 1
    var positions = Set<Int>()
    var iCount = 1

    for i in 1...K {
        let nextPosition = telepoter[position - 1]
        let previousCount = positions.count
        positions.insert(nextPosition)

        if previousCount == positions.count {
            iCount = i
            break
        }

        position = nextPosition
    }

    var roop = Set<Int>()
    var roopPositions: [Int] = []
    for j in (iCount-1)...K {
        let nextPosition = telepoter[position - 1]
        let previousCount = roop.count
        position = nextPosition
        roop.insert(nextPosition)
        roopPositions.append(nextPosition)

        if previousCount == roop.count {
            // 修正
            let cycle = roop.count

            let answerIndex = (K - (iCount - cycle)) % cycle
            print(roopPositions[answerIndex])
            break
        }
    }
}
mainD()


/// 10
var (_,k) = cin.pair
/// [2, 3, 4, 5, 6, 4]
/// [1, 2, 3, 4, 5, 3]
let A = cin.array.map { $0-1 }
/// []
var seen = [Int]()
/// 0
var current = 0

while true {
    seen.append(current)
    current = A[current]
    k -= 1

    if k == 0 {
        print(current+1)
        exit(0)
    }

    if seen.contains(current) {
        break
    }
}

/// seen: [0, 1, 2, 3, 4, 5]
/// current: 5
/// loop: [4, 5, 3]
/// k: 10 - 5 = 5

let loop = Array(seen[seen.firstIndex(of: current)!..<seen.count])

/// res = 5%3 = 2
/// loop[2] = 3
/// ans: 5 (index: 4)

let ans = loop[k%loop.count]
print(ans+1)

// MARK: #### 以下、ライブラリ ####

import Foundation
#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif

enum cin {
    // 123
    static var int: Int { Int(readLine()!)! }
    // 12 23
    static var pair: (Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!) }
    // 12 23 34
    static var triple: (Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!) }
    // AtCoder
    static var str: String { readLine()! }
    // At Coder
    static var arrayStr: [String] { str.components(separatedBy: " ") }
    // 1 2 3 4
    static var array: [Int] { str.components(separatedBy: " ").map { Int($0)! } }
    // 1
    // 2
    // 3
    static func v_array(count: Int) -> [Int] { (0..<count).map { _ in int } }
}

extension Int {
    // 123 -> [1, 2, 3]
    var digits: [Int] { Array(String(self)).map { Int(String($0))! } }
}

extension Array where Element == Int {
    // [2, 1, 3, 2] -> 8
    var sum: Int { self.reduce(0, +) }
    // [2, 1, 3, 2] -> [1, 2, 2, 3]
    var orderBy: [Int] { sorted() }
    // [2, 1, 3, 2] -> [3, 2, 2, 1]
    var orderByDesc: [Int] { sorted(by: { $0 > $1 }) }
    // [2, 1, 3, 2] -> [2, 1, 3]
    var distinct: [Int] { Array(Set(self)) }
}

precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
infix operator ^^ : PowerPrecedence
func ^^ (radix: Int, power: Int) -> Int {
    return Int(pow(Double(radix), Double(power)))
}

extension String {
    // e.g. cin.line.regex(match: "^(dream|dreamer|erase|eraser)*$")
    func regex(match pattern: String) -> Bool {
        let regex = try! NSRegularExpression(pattern: pattern)
        return regex.firstMatch(in: self, range: NSRange(location: 0, length: self.count)) != nil
    }
    // "ABC"[1] -> "B"
    subscript(i: Int) -> Character {
        get {
            self[index(at: i)]
        }
        set(char) {
            var characters = Array(self)
            characters[i] = char
            self = String(characters)
        }
    }
    func index(at offset: Int) -> String.Index { index(startIndex, offsetBy: offset) }
    // "ABC".swapAt(0, 1) -> "BAC"
    mutating func swapAt(_ index1: Int, _ index2: Int) {
        var characters = Array(self)
        characters.swapAt(index1, index2)
        self = String(characters)
    }
}


/// 10
var (_,k) = cin.pair
/// [2, 3, 4, 5, 6, 4]
/// [1, 2, 3, 4, 5, 3]
let A = cin.array.map { $0-1 }
/// []
var seen = [Int]()
/// 0
var current = 0

while true {
    seen.append(current)
    current = A[current]
    k -= 1

    if k == 0 {
        break
    }

    if seen.contains(current) {
        break
    }
}

/// seen: [0, 1, 2, 3, 4, 5]
/// current: 5
/// loop: [4, 5, 3]
/// k: 10 - 5 = 5

let loop = Array(seen[seen.firstIndex(of: current)!..<seen.count])

/// res = 5%3 = 2
/// loop[2] = 3
/// ans: 5 (index: 4)

let ans = loop[k%loop.count]
print(ans+1)

// MARK: #### 以下、ライブラリ ####

import Foundation
#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif

enum cin {
    // 123
    static var int: Int { Int(readLine()!)! }
    // 12 23
    static var pair: (Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!) }
    // 12 23 34
    static var triple: (Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!) }
    // AtCoder
    static var str: String { readLine()! }
    // At Coder
    static var arrayStr: [String] { str.components(separatedBy: " ") }
    // 1 2 3 4
    static var array: [Int] { str.components(separatedBy: " ").map { Int($0)! } }
    // 1
    // 2
    // 3
    static func v_array(count: Int) -> [Int] { (0..<count).map { _ in int } }
}

extension Int {
    // 123 -> [1, 2, 3]
    var digits: [Int] { Array(String(self)).map { Int(String($0))! } }
}

extension Array where Element == Int {
    // [2, 1, 3, 2] -> 8
    var sum: Int { self.reduce(0, +) }
    // [2, 1, 3, 2] -> [1, 2, 2, 3]
    var orderBy: [Int] { sorted() }
    // [2, 1, 3, 2] -> [3, 2, 2, 1]
    var orderByDesc: [Int] { sorted(by: { $0 > $1 }) }
    // [2, 1, 3, 2] -> [2, 1, 3]
    var distinct: [Int] { Array(Set(self)) }
}

precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
infix operator ^^ : PowerPrecedence
func ^^ (radix: Int, power: Int) -> Int {
    return Int(pow(Double(radix), Double(power)))
}

extension String {
    // e.g. cin.line.regex(match: "^(dream|dreamer|erase|eraser)*$")
    func regex(match pattern: String) -> Bool {
        let regex = try! NSRegularExpression(pattern: pattern)
        return regex.firstMatch(in: self, range: NSRange(location: 0, length: self.count)) != nil
    }
    // "ABC"[1] -> "B"
    subscript(i: Int) -> Character {
        get {
            self[index(at: i)]
        }
        set(char) {
            var characters = Array(self)
            characters[i] = char
            self = String(characters)
        }
    }
    func index(at offset: Int) -> String.Index { index(startIndex, offsetBy: offset) }
    // "ABC".swapAt(0, 1) -> "BAC"
    mutating func swapAt(_ index1: Int, _ index2: Int) {
        var characters = Array(self)
        characters.swapAt(index1, index2)
        self = String(characters)
    }
}


import * as fs from 'fs'

const input = fs.readFileSync('/dev/stdin', 'utf8').split('\n')
const n = +input[0].split(' ')[0]
const k = BigInt(input[0].split(' ')[1])
const a = input[1].split(' ').map(x => +x)
let cur = 0
if (k <= n) {
  for (let i = 0; i < k; i++) {
    cur = a[cur] - 1
  }
} else {
  let visited = new Array(n).fill(-1)
  visited[0] = 0
  let teleport = 0
  let loop = 0
  for (let i = 0; i < n; i++) {
    cur = a[cur] - 1
    teleport = i + 1
    if visited[cur] >= 0 {
      loop = teleport - visited[cur]
      break
    } else {
      visited[cur] = teleport
    }
  }
  for (let i = 0; i < (k - BigInt(teleport)) % BigInt(loop); i++) {
    cur = a[cur] - 1
  }
}
console.log(cur + 1)


import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const n = +input[0].split(" ")[0];
let _k = BigInt(input[0].split(" ")[1]);
const a = input[1].split(" ").map((x: string): number => (+x) - 1);

let current = 0;
const visited = new Map();
let count = 0;
while (!visited.has(current)) {
	visited.set(current, count);
	current = a[current];
	count++;
}
const d = BigInt(visited.get(current)!);
const loop_length = BigInt(count) - d;
const k = _k < d + loop_length ? Number(_k) : Number(d + ((_k - d) % loop_length));
current = 0;
for (let i = 0; i < k; i++) {
	current = a[current];
}
console.log(current + 1);


import { count } from 'console';

process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const [n, k] = inputs[0].split(' ').map(BigInt);
  const city = inputs[1].split(' ').map(BigInt);
  let roopSet = new Set<number>();
  let roop: number[] = [];
  let roopStart = 0;
  let teleport = 1;
  let isRoopExist = false;

  for (let i = 1; i <= k; i++) {
    if (!roopSet.has(teleport)) {
      roopSet.add(teleport);
    } else if (i < k && roopSet.has(teleport)) {
      roopSet.forEach((value) => roop.push(value));
      roop = roop.slice(roop.indexOf(teleport), roop.length);
      isRoopExist = true;
      break;
    }
    teleport = Number(city[teleport - 1]);
    roopStart++;
  }

  if (isRoopExist) {
    teleport = roop[Number((k - BigInt(roopStart)) % BigInt(roop.length))];
  }

  console.log(teleport);
}


import { count } from 'console';

process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const [n, k] = inputs[0].split(' ').map(BigInt);
  const city = inputs[1].split(' ').map(BigInt);
  let roop: number[] = [];
  let roopStart = 0;
  let teleport = 1;
  let isRoopExist = false;

  for (let i = 1; i <= k; i++) {
    if (roop.indexOf(teleport) === -1) {
      roop.push(teleport);
    } else if (i < k && roop.indexOf(teleport) !== -1) {
      roopStart = roop.indexOf(teleport);
      roop = roop.slice(roopStart, roop.length);
      isRoopExist = true;
      break;
    }
    teleport = Number(city[teleport - 1]);
  }

  if (isRoopExist) {
    teleport = roop[Number((k - BigInt(roopStart)) % BigInt(roop.length))];
  }

  console.log(teleport);
}


import * as fs from 'fs'

const input = fs.readFileSync('/dev/stdin', 'utf8').split('\n')
const n = +input[0].split(' ')[0]
const k = BigInt(input[0].split(' ')[1])
const a = input[1].split(' ').map(x => +x)
let visited = new Array(n).fill(-1)
visited[0] = 0
let cur = 0
let teleport = 0
let loop = 0
for (let i = 0; i < n; i++) {
  cur = a[cur] - 1
  teleport = i + 1
  if visited[cur] >= 0 {
    loop = teleport - visited[cur]
    break
  } else {
    visited[cur] = teleport
  }
}
for (let i = 0; i < (k - BigInt(teleport)) % BigInt(loop); i++) {
  cur = a[cur] - 1
}
console.log(cur + 1)


import * as fs from 'fs'

const input = fs.readFileSync('/dev/stdin', 'utf8').split('\n')
const [n, k] = input[0].split(' ').map(x => +x)
const a = input[1].split(' ').map(x => +x)
let visited = new Array(n).fill(-1)
visited[0] = 0
let cur = 0
let teleport = 0
let loop = 0
for (let i = 0; i < n; i++) {
  cur = a[cur] - 1
  teleport = i + 1
  if visited[cur] >= 0 {
    loop = teleport - visited[cur]
    break
  } else {
    visited[cur] = teleport
  }
}
for (let i = 0; i < (k - teleport) % loop; i++) {
  cur = a[cur] - 1
}
console.log(cur + 1)


def factorial(n):
    ans = 1
    for i in range(2, n + 1):
        ans = ans * i % 1000000007
    return ans
n, m = map(int, input().split())
MOD = 10**9 + 7
if n == m:
    print(2 * factorial(n) ** 2 % MOD)
elif abs(n - m) == 1:
    print(factorial(min(m, n)) ** 2 * max(m, n) % MOD)
else:
    print(0)


import math

def factorial(n):
    val = 1
    for i in range(2, n + 1):
        val =  val * i % 1000000007
    return val

n,m= (int(i) for i in input().split())

if n==m:
    a = factorial(n)
    print(2 * a * a % 1000000007)
elif abs(n-m) == 1:
    a = factorial(min(m,n))
    print(a * a * max(m,n) % 1000000007)
else:
    print(0)


# ABC065C - Reconciled? (ARC076C)
def factorial_mod(x: int) -> int:
    MOD = 10 ** 9 + 7  # change the value if needed
    ret = 1
    for i in range(1, x + 1):
        ret = (ret * i) % MOD
    return ret

def main():
    n, m = list(map(int, input().rstrip().split()))
    MOD = 10 ** 9 + 7
    n, m = min(n, m), max(n, m)
    dif = m - n
    if dif > 1:  # must be ...DDM...
        print(0)
    else:
        if dif == 0:  # start with either D or M (DM..., MD...)
            ans = (factorial_mod(n) ** 2 * 2) % MOD  # n == m -> (n!)^2 * 2
        else:  # sandwich (DMD or MDM)
            ans = (factorial_mod(n) ** 2 * m) % MOD  # n + 1 == m -> (n!)^2 * m
        print(ans)

if __name__ == "__main__":
    main()


n,m = map(int, input().split())
if n > m:
    n,m = m,n
ans = 1
if m==n:

    while n > 0:
        ans *= n
        ans %= 10**9+7
        n -= 1
    ans = (2*(ans**2))%(10**9+7)
    print(ans)

elif m - n == 1:
    while n > 0:
        ans *= n
        ans %= 10**9+7
        n -= 1

    ans = (ans * (ans*m % 10**9+7)) % (10**9+7)
    print(ans)
else:
    print(0)


N, M = map(int, input().split())
from math import factorial
mod = 10**9+7

if abs(N-M) > 1:
    print(0)
else:
    print(2*factorial(N)*factorial(M)%mod)


n, m = map(int, input().split())
p = 10**9 + 7

def fac(n):
  x = 1
  for i in range(1,n+1):
    x *= i
  return x

nf = fac(n) % p
mf = fac(m) % p

if abs(n-m) > 1:
  ans = 0

elif n == m:
  ans = nf * mf * 2

else:
  ans = nf * mf

print(ans % p)


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.ConnectException;
import java.rmi.dgc.Lease;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		main.out.close();
	}

	// ======================================================================
	final long MOD = (long)(1e9) + 7;
	long calc(long X) {
		long ans = 1;
		for(long i = 1; i <= X; i++) {
			ans = (ans * i) % MOD;;
		}
		return ans;
	}
	public void solve() {
		long N = nl();
		long M = nl();
		if(Math.abs(N - M) > 1) {
			out.println(0);
			return;
		}
		long ans = (calc(N) * calc(M)) % MOD;
		if(N == M)	ans = (ans * 2) % MOD;
		out.println(ans);
	}

	// ------------------------------------------
	// ライブラリ
	// ------------------------------------------
	// Print
	private PrintWriter out = new PrintWriter(System.out);

	// Scanner
	private FastScanner scan = new FastScanner();

	int ni() {
		return scan.nextInt();
	}

	int[] ni(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = ni();
		}
		return a;
	}

	int[][] ni(int y, int x) {
		int[][] a = new int[y][x];
		for (int i = 0; i < y; i++) {
			for (int j = 0; j < x; j++) {
				a[i][j] = ni();
			}
		}
		return a;
	}

	long nl() {
		return scan.nextLong();
	}

	long[] nl(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = nl();
		}
		return a;
	}

	long[][] nl(int y, int x) {
		long[][] a = new long[y][x];
		for (int i = 0; i < y; i++) {
			for (int j = 0; j < x; j++) {
				a[i][j] = nl();
			}
		}
		return a;
	}

	String ns() {
		return scan.next();
	}

	String[] ns(int n) {
		String[] a = new String[n];
		for (int i = 0; i < n; i++) {
			a[i] = ns();
		}
		return a;
	}

	String[][] ns(int y, int x) {
		String[][] a = new String[y][x];
		for (int i = 0; i < y; i++) {
			for (int j = 0; j < x; j++) {
				a[i][j] = ns();
			}
		}
		return a;
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		new Main().solve();
		pw.close();
	}

	/**
	 * ASCII
	 * 0 48
	 * A 65
	 * a 97
	 */

	static PrintWriter pw = new PrintWriter(System.out);

	long MOD = 1_000_000_007;

	void solve() {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		if (Math.abs(N-M) > 1) rout(0);
		long ans = 1;
		if (N == M) ans = 2;
		else ans = Math.max(N, M);
		long t = 1;
		for (int i = Math.min(N, M); i > 0; i--) {
			t *= i;
			t %= MOD;
		}
		t *= t;
		t %= MOD;
		ans *= t;
		ans %= MOD;
		out(ans);
	}

	class UnionFind {
		int[] parents;
		int[] counts;

		public UnionFind(int size) {
			parents = new int[size];
			counts = new int[size];
			for (int i = 0; i < size; i++) {
				parents[i] = i;
				counts[i] = 1;
			}
		}

		public int find(int a) {
			if (parents[a] == a) return a;
			parents[a] = find(parents[a]);
			return parents[a];
		}

		public void unite(int a, int b) {
			a = find(a);
			b = find(b);
			if (a == b) return;
			if (counts[a] < counts[b]) {
				parents[a] = b;
				counts[b] += counts[a];
			} else {
				parents[b] = a;
				counts[a] += counts[b];
			}
		}

		public boolean differ(int a, int b) {
			a = find(a);
			b = find(b);
			return a != b;
		}

		public int count(int a) {
			return counts[find(a)];
		}
	}

	class Combination {
		final int mod;
		final int max;

		final long[] fact;
		final long[] inv;
		final long[] invfact;

		public Combination(int n) {
			this(n, 1_000_000_007);
		}

		public Combination(int n, int mod) {
			this.mod = mod;
			max = n + 1;
			fact = new long[max];
			invfact = new long[max];
			inv = new long[max];

			inv[1] = 1;
			for (int i = 2; i < inv.length; i++) {
				inv[i] = inv[mod % i] * (mod - mod / i) % mod;
			}

			fact[0] = 1;
			invfact[0] = 1;
			for (int i = 1; i < inv.length; i++) {
				fact[i] = i * fact[i - 1] % mod;
				invfact[i] = inv[i] * invfact[i - 1] % mod;
			}
		}

		public long get(int n, int r) {
			return fact[n] * invfact[n - r] % mod * invfact[r] % mod;
		}
	}

	public long gcd(long a, long b) {
		if (b == 0) return a;
		else return gcd(b, a%b);
	}

	public void reverse(int[] a) {
		int last = a.length-1;
		int n = a.length / 2;
		for (int i = 0; i < n; i++) {
			int t = a[i];
			a[i] = a[last-i];
			a[last-i] = t;
		}
	}

	public void reverse(long[] a) {
		int last = a.length-1;
		int n = a.length / 2;
		for (int i = 0; i < n; i++) {
			long t = a[i];
			a[i] = a[last-i];
			a[last-i] = t;
		}
	}

	void out(String a) {
		pw.println(a);
	}
	void out(boolean a) {
		pw.println(a);
	}

	void out(int a) {
		pw.println(a);
	}

	void out(long a) {
		pw.println(a);
	}

	void out(double a) {
		pw.println(a);
	}

	void out(char a) {
		pw.println(a);
	}

	void rout(String a) {
		out(a);
		pw.close();
		System.exit(0);
	}
	void rout(int a) {
		out(a);
		pw.close();
		System.exit(0);
	}
	void rout(long a) {
		out(a);
		pw.close();
		System.exit(0);
	}
	void rout(double a) {
		out(a);
		pw.close();
		System.exit(0);
	}
	void rout(char a) {
		out(a);
		pw.close();
		System.exit(0);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n, m;
    int MOD = 1000000007;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        m = sc.nextInt();
        solve();
    }

    void solve() {
        if (n > m) {
            int temp = n;
            n = m;
            m = temp;
        }
        if (m - n > 1) {
            System.out.println(0);
            return;
        }
        long ans = 0;
        long[] facts = fillFactorial(m, MOD);
        if (n == m) {
            ans = 2 * facts[n] * facts[m] % MOD;
        } else {
            ans = facts[n] * facts[m] % MOD;
        }
        System.out.println(ans);
    }

    long[] fillFactorial(int max, int mod) {
        long[] facts = new long[max + 1];
        facts[0] = 1;
        for (int i = 1; i < facts.length; i++) {
            facts[i] = facts[i - 1] * i % mod;
        }
        return facts;
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;

public class Main{
    final int MOD = 1000000007;
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        if(Math.abs(n - m) >= 2){
            System.out.println(0);
            return;
        }
        long out = 1;
        for(int i = 2; i <= n; i++){
            out *= i;
            if(out > MOD) out %= MOD;
        }
        for(int i = 2; i <= m; i++){
            out *= i;
            if(out > MOD) out %= MOD;
        }
        System.out.println((out * 2) % MOD);
    }

    public static void main(String[] args){
        new Main().solve();
    }
}


import java.util.*;

public class Main{
    final int MOD = 1000000007;
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        if(Math.abs(n - m) >= 2){
            System.out.println(0);
            return;
        }
        long out = 1;
        for(int i = 2; i <= n; i++){
            out *= i;
            if(out > MOD) out %= MOD;
        }
        for(int i = 2; i <= m; i++){
            out *= i;
            if(out > MOD) out %= MOD;
        }
        System.out.println((out % MOD) * 2 % MOD);
    }

    public static void main(String[] args){
        new Main().solve();
    }
}


import java.util.*;
public class Main {
    public static void main(String[] args ){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int mod = (int) Math.pow(10,9) + 7;

        if (Math.abs(m-n) > 1) {
            System.out.println(0);
            return;
        }
        long ans = 1;
        for (int i = 2; i <= n; i++) {
            ans *= i;
            ans %= mod;
        }
        for (int i = 2; i <= n; i++) {
            ans *= i;
            ans %= mod;
        }
        System.out.println(n == m ? 2 * ans % mod: ans);
    }

}


#include <cstdio>

using namespace std;

const int MOD = 1000000007;
int n, m;
int main()
{
    scanf("%d%d", &n, &m);
    if(n > m + 1 || m > n + 1) printf("0");
    else{
        if(n < m) ++n, --m;
        if(n == m){
            int f1 = 1;
            for(int i = 2; i <= n ; ++i)
                f1 = (1LL * f1 * i) % MOD;
            f1 = (1LL * f1 * f1 * 2) % MOD;
            printf("%d", f1);
        }
        else if(n > m){
            int f1 = 1;
            for(int i = 2; i <= m ; ++i)
                f1 = (1LL * f1 * i) % MOD;
            f1= (1LL *f1 * f1) % MOD;
            f1 = (1LL * f1 * n) % MOD;
            printf("%d", f1);
        }

    }
    return 0;
}


#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;

ll func(long n) {
    ll ans=1;
    long i;
    for(i=1; i<=n; i++) {
        ans = ans * i %MOD;
    }
    return ans;
}

int main(int argc, char* argv[])
{
    long n,m;
    scanf("%ld%ld", &n, &m);

    if(n==m) {
        printf("%lld\n", func(n) * func(n) * 2 % MOD);
    }
    else if (n==m+1) {
        printf("%lld\n", func(n) * func(m) % MOD);
    }
    else if (m==n+1) {
        printf("%lld\n", func(n) * func(m) % MOD);
    }
    else {
        printf("0\n");
    }

    return 0;
}


#include <stdio.h>
#define y 1000000007
int main(void){
  int n,m,i;
  long dog=1,mon=1,ans;
  scanf("%d%d",&n,&m);
  if (n-m>1||m-n>1){
    printf("0\n");
    return 0;
  }
  for (i=2;i<=n;i++) dog=(dog*i)%y;
  for (i=2;i<=m;i++) mon=(mon*i)%y;
  ans=dog*mon%y;
  if (n==m) ans=ans*2%y;
  printf("%ld\n",ans);
  return 0;
}


#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;

// 階乗mod
ll fmod(ll n){
    ll ans = 1;
    for(ll i = 1; i <= n; i++){
        ans *= i;
        ans %= MOD;
    }

    return ans;
}

int main(){
    ll N, M;
    cin >> N >> M;

    ll
    if(N == M){
        cout << (2 * fmod(N) % MOD) * fmod(M) % MOD << endl;
    }else if(abs(N - M) == 1){
        if(N < M){
            swap(N, M);
        }
        cout << fmod(N) * fmod(M) % MOD << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll INFL = 1e18;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;

    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

///////////////////////////////////////////////////////////////////////////////////

int main(){
    int n,m;
    cin >> n >> m;
    long long N = 1, M = 1;
    for (int i = 1;i <= m;i++){
        M *= i;
    }
    for (int i = 1;i <= n;i++){
        N *= i;
    }
    if (abs(m-n) >= 2){
        cout << 0 << endl;
    }
    else if (abs(m-n) == 1){
        cout << M*N << endl;
        return 0;
    } else {
        cout << 2*M*N << endl;
        return 0;
    }
}


#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

ll f(ll n)
{
  if (n == 1) return 1;
  return ((n * f(n - 1)) % MOD);
}

void solve()
{
  int n, m;
  cin >> n >> m;
  if ( abs(n - m) > 1)
  {
    cout << 0;
    return;
  }
  ll ans = 1 + (n == m);
  ans *= f(n);
  ans *= f(m);
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	long long N, M;
	scanf("%lld %lld", &N, &M);

	long long i, dog = 1, monkey = 1;
	for (i = 2; i <= N; i++) dog = dog * i % 1000000007;
	for (i = 2; i <= M; i++) monkey = monkey * i % 1000000007;

	if (llabs(N - M) >= 2) printf("0\n");
	else if (llabs(N - M) == 1) printf("%lld\n", dog * monkey % 1000000007);
	else printf("%lld\n", dog * monkey * 2 % 1000000007);
	fflush(stdout);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {

  long n,m;
  scanf("%ld %ld", &n, &m);
  if (labs(n-m) > 1) {
    printf("0\n");
    return 0;
  }
  long mod = pow(10,9)+7;
  long answer = 1;
  if (labs(n-m) == 0) {
    answer *= 2;
  }
  for (long i = 1; i <= n; i++) {
    answer *= i;
    answer %= mod;
  }
  for (long i = 1; i <= m; i++) {
    answer *= i;
    answer %= mod;
  }
  printf("%ld\n", answer);

  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) {
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) {
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

lli f[MAX];
void fact(int n) {
  for (lli i = 1; i <= n; i++ )
    f[i] = f[i-1] * i % MOD;
}

int main(void) {
  lli N, M;
  scanf("%lld %lld", &N, &M);

  f[0] = 1;
  fact(100000);
  lli dif = llabs(N - M);
  if ( dif != 0 && dif != 1 ) {
    printf("0\n");
    return 0;
  }
  if ( dif == 0 ) {
    printf("%lld\n", ((f[N] * f[M]) % MOD) * 2 % MOD);
    return 0;
  }
  printf("%lld\n", f[N] * f[M] % MOD);
  return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
long long int a,b,ans,mod,i,modp[200001];
  scanf("%lld %lld",&a,&b);
  mod=pow(10,9)+7;
  modp[0]=1;
  for(i=1;i<200001;++i)
  {
  modp[i]=(modp[i-1]*i)%mod;
  }
  ans=(modp[a]*modp[b])%mod;
  if(llabs(a-b)>1) printf("0");
  else if(a==b) printf("%lld",ans*2);
  else printf("%lld",ans);
return 0;}


#include<stdio.h>
#include<math.h>
int main()
{
long long int a,b,ans,mod,i,modp[200001];
  scanf("%lld %lld",&a,&b);
  mod=pow(10,9)+7;
  modp[0]=1;
  for(i=1;i<200001;++i)
  {
  modp[i]=(modp[i-1]*i)%mod;
  }
  ans=(modp[a]*modp[b])%mod;
  if(llabs(a-b)>1) printf("0");
  else printf("%lld",ans);
return 0;}


#include<stdio.h>
#include<math.h>
int main()
{
long long int a,b,ans,mod,i,modp[200001];
  scanf("%lld %lld",&a,&b);
  mod=pow(10,9)+7;
  modp[0]=1
  for(i=1;i<200001;++i)
  {
  modp[i]=(modp[i-1]*i)%mod;
  }
  ans=(modp[a]*modp[b])%mod;
  if(abs(a-b)>1) printf("0");
  else printf("%lld",ans);
return 0;}


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);

    // 差が2以上あると交互に並べられない
    if(Math.abs(N - M) > 1) {
        console.log(0);
        return;
    }

    const MOD = 1e9 + 7;
    let answer = 1;

    for(let i=1; i<=N; i++) {
        answer = (answer % MOD) * (i % MOD);
    }

    for(let i=1; i<=M; i++) {
        answer = (answer % MOD) * (i % MOD);
    }

    /* -----------------------------------------------------
       差が0のときは、組み合わせが2通り 例：犬猿犬猿, 猿犬猿犬
       差が1のときは、組み合わせが1通り 例：犬猿犬猿犬
       それによって答えを2倍にするかどうか分ける
    --------------------------------------------------------*/
    console.log(answer * ((N == M) + 1) % MOD);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


'use strict'

function main(input) {
  input = input.split(' ').map(v => ~~v)
  const n = input[0]
  const m = input[1]

  const limit = 1e9 + 7 //(Math.pow(10, 9) + 7)

  //交互に並べられない
  if (Math.abs(n - m) >= 2) {
    console.log(0)
    return
  }

  let nn = 1
  for (let i = 2; i <= n; i++) {
    nn *= i
    if (nn >= limit) {
      nn = nn % limit
    }
  }
  // let mm = 1
  for (let i = 2; i <= m; i++) {
    nn *= i
    if (nn >= limit) {
      nn = nn % limit
    }
  }
  // console.log(nn,mm)

  let tmp = nn % limit
  // console.log(tmp)
  if (n == m) {
    tmp = 2 * tmp
  }
  const ans = tmp % limit

  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);

    // 差が2以上あると交互に並べられない
    if(Math.abs(N - M) > 1) {
        console.log(0);
        return;
    }

    const MOD = 1e9 + 7;
    let answer = 1;

    for(let i=1; i<=N; i++) {
        answer = (answer % MOD) * (i % MOD);
    }

    for(let i=1; i<=M; i++) {
        answer = (answer % MOD) * (i % MOD);
    }

    /* -----------------------------------------------------
       差が1のときは、組み合わせが2通り 例：犬猿犬猿, 猿犬猿犬
       差が0のときは、組み合わせが1通り 例：犬猿犬猿犬
       それによって答えを2倍にするかどうか分ける
    --------------------------------------------------------*/
    console.log(answer * ((N == M) + 1) % MOD);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)

const fn = (x) => {
    let ans = 1n
    for(let i = 1n; i<=x; i++){
        ans *= i
    }
    return ans
}
const Main = () => {
    const [n, m ] = nextIntArray()
    let ans = fn(n) * fn(m) * 2n % 1000000007n
    console.log(Number(ans))
}
Main()


"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)

const fn = (x) => {
    let ans = 1n
    for(let i = 1n; i<=x; i++){
        ans *= i
    }
    return ans
}
const Main = () => {
    const [n, m ] = nextIntArray()
    let ans = fn(n) * fn(m) * 2n / 1000000007n
    console.log(Number(ans))
}
Main()


"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)

const fn = (x) => {
    let ans = 1n
    for(let i = 1n; i<=x; i++){
        ans *= i
    }
    return ans
}
const Main = () => {
    const [n, m ] = nextIntArray()
    let ans = fn(n) * fn(m) * 2n
    while(ans > 1000000007n){
        ans /= 1000000007n
    }
    console.log(Number(ans))
}
Main()


package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	N := getInt()
	M := getInt()

	if abs(N - M) >= 2 {
		fmt.Println(0)
		return
	}

	result := factMod(N)
	result = calcMod(result * factMod(M))

	if abs(N - M) == 0 {
		result = calcMod(result * 2)
	}

	fmt.Println(result)
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func bfs(c int, graph *Graph) {
	next := make([]int, 0)
	next = append(next, c)
	visited := make(map[int]struct{})

	for ; len(next) != 0; {
		u := next[0]
		next = next[1:]
		visited[u] = struct{}{}

		for _, v := range graph.edges[u] {
			_, flag := visited[v]
			if flag {
				continue
			}

			// なにか処理

			next = append(next, v)
		}
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getIntArray(n int) []int {
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = getInt()
	}
	return array
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func getStringArray(n int) []string {
	array := make([]string, n)
	for i := 0; i < n; i++ {
		array[i] = getString()
	}
	return array
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return calcMod(n * powMod(n, p-1))
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func isPrime(n int) bool {
	if n < 2 {
		return false
	} else if n == 2 {
		return true
	} else if n % 2 == 0 {
		return false
	}

	sqrtN := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqrtN; i += 2 {
		if n % i == 0 {
			return false
		}
	}

	return true
}

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

func makeRange(min, max int) []int {
	a := make([]int, max-min+1)
	for i := range a {
		a[i] = min + i
	}
	return a
}

func powerset2(nums []int) [][]int {
	length := int(math.Pow(2, float64(len(nums))))
	result := make([][]int, length)

	index := 0
	result[index] = []int{}
	index++

	for _, n := range nums {
		max := index
		for i := 0; i < max; i++ {
			result[index] = copyAndAppend(result[i], n)
			index++
		}
	}

	return result
}

func copyAndAppend(nums []int, n int) []int {
	dst := make([]int, len(nums)+1)
	copy(dst, nums)
	dst[len(nums)] = n
	return dst
}

func calcGcd(x, y int) int {
	if y == 0 {
		return x
	} else if x >= y {
		return calcGcd(y, x % y)
	} else {
		return calcGcd(x, y % x)
	}
}

func getDivisor(n int) []int {
	var divisor []int
	divisor = append(divisor, 1)
	if n != 1 {
		divisor = append(divisor, n)
	}

	sqrt := int(math.Sqrt(float64(n)))
	for i := 2; i <= sqrt; i++ {
		if n % i == 0 {
			divisor = append(divisor, i)
			divisor = append(divisor, n/i)
		}
	}
	return divisor
}

type intHeap []int

func (h intHeap) Len() int {
	return len(h)
}

func (h intHeap) Less(i, j int) bool {
	return h[i] > h[j]
}

func (h intHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func initHeap() *intHeap {
	ih := &intHeap{}
	heap.Init(ih)
	return ih
}

func (h *intHeap) pushHeap(n int) {
	heap.Push(h, n)
}

func (h *intHeap) popHeap() int {
	return heap.Pop(h).(int)
}

func factMod(n int) int {
	value := 1
	for ; n > 1; n-- {
		value = calcMod(value * n)
	}
	return value
}

func combinationMod(n, k int) int {
	factN := factMod(n)
	factK := factMod(k)
	factNK := factMod(n - k)
	factKR := powMod(factK, mod - 2)
	factNKR := powMod(factNK, mod - 2)
	return calcMod(factN * calcMod(factKR * factNKR))
}


package main

import "fmt"

const mod int = 1000000007

func main() {
	var N, M, r int
	fmt.Scan(&N, &M)

	diff := Abs(N - M)
	if diff >= 2 {
		fmt.Println(0)
		return
	}
	w := make([]int, 100010)
	w[1] = 1
	for i := 2; i < len(w); i++ {
		w[i] = (w[i-1] * i) % mod
	}
	r = (w[N] * w[M]) % mod
	if diff == 0 {
		r = (r * 2) % mod
	}
	fmt.Println(r)
}
func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const mod = 1e9 + 7

func main() {
	sc.Split(bufio.ScanWords)

	N, M := getInt(), getInt()
	if abs(N-M) > 1 {
		out(0)
		return
	}
	ans := 1
	for i := 1; i <= N; i++ {
		ans *= i
		ans %= mod
	}
	for i := 1; i <= M; i++ {
		ans *= i
		ans %= mod
	}
	if N == M {
		ans *= 2
		ans %= mod
	}
	out(ans)
}


package main

import (
	"fmt"
)

const mod = 1000000007

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	var ans int
	if n == m {
		p := permutation(n)
		ans = 2 * p * p
	} else if abs(n-m) == 1 {
		p := permutation(min(n, m))
		ans = p * p * max(n, m)
	} else {
		ans = 0
	}
	fmt.Println(ans % mod)
}

func permutation(n int) int {
	v := 1
	for i := 0; i < n; i++ {
		v *= n - i
		v %= mod
	}
	return v
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


package main

import (
	"fmt"
	"math"
)

func permutation(n int, k int) int {
	v := 1
	if 0 < k && k <= n {
		for i := 0; i < k; i++ {
			v *= (n - i)
			v = v % int(math.Pow10(9)+7)
		}
	} else if k > n {
		v = 0
	}
	return v
}

func factorial(n int) int {
	return permutation(n, n-1)
}

func main() {
	// Code for C - Reconciled?
	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	var count int
	if N == M {
		count = count + 2
	}

	count += factorial(N)
	count += factorial(M)
	count = count % int(math.Pow10(9)+7)
	fmt.Println(count)
}


package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	if N < M {
		N, M = M, N
	}
	var ans int
	if N-M >= 2 {
		ans = 0
	} else {
		ans = ModFactorial(N) * ModFactorial(M)
		if N == M {
			ans = ans * 2 % Mod
		}
	}
	fmt.Println(ans)
}

const Mod = int(1e9) + 7

func ModFactorial(n int) int { return fac[n] }

var fac []int

func init() {
	const MAX = 1e5
	fac = make([]int, MAX+1)
	fac[0], fac[1] = 1, 1
	for i := 2; i <= MAX; i++ {
		fac[i] = fac[i-1] * i % Mod
	}
}


def fact(n, mod)
  f = 1
  n.downto(1){|i|
    f = (f * i) % mod
  }
  f
end

N, M = gets.chomp.split(" ").map(&:to_i)
MOD = 10 ** 9 + 7

if (N-M).abs > 1 then
  puts 0
elsif N == M then
  wk = fact(N, MOD)
  puts (2 * wk * wk) % MOD
else
  w = [N, M].min
  wk = fact(w, MOD)
  puts ((w+1) * wk * wk) % MOD
end


MODS = 10**9 + 7

def mod_fact(count)
  x = 1
  2.upto(count) do |i|
    x = x * i % MODS
  end
  x
end

n, m = gets.split.map(&:to_i).minmax
case m - n
when 0
  p mod_fact(n)**2 * 2 % MODS
when 1
  p mod_fact(n)**2 * m % MODS
else
  p 0
end


NN = 1000000007

n, m = gets.chomp.split(" ").map(&:to_i)

if (n-m).abs > 1
  puts 0
  exit
end

def fact(n)
  x = 1
  for i in 2..n
    x = x * i % NN
  end
  return x
end

if n == m
  puts fact(n) ** 2 * 2 % NN
elsif n < m
  puts (fact(n) ** 2 * m) % NN
else
  puts (fact(m) ** 2 * n) % NN
end


M = 10**9+7
def ext(x)
  s = 1
  for i in 1..x
    s *= (i%M)
  end
  return s
end

n,m = gets.strip.split.map(&:to_i)
if (n-m).abs >= 2
  puts 0
  exit
end
if (n-m).abs == 1
  puts (ext(n)*ext(m))%M
  exit
end
if n == m
  puts (2*ext(n)*ext(m))%M
  exit
end


n, m = gets.chomp.split(" ").map(&:to_i)
sa = n - m
count = 1
def ans(n)
    if n > 1
        n * ans(n-1)
    else
        return 1
    end
end
if sa == 0
    ans = ans(n) * ans(n) * 2
elsif sa == 1
    ans = ans([n,m].min) * ans([n,m].max)
else
    ans = 0
end
puts ans


n=gets.split.map(&:to_i)
if n[0]==n[1]
    result=2
    for i in 1..n[0]
        result*=i
        result*=i
        result%=10**9+7
    end
    result%=10**9+7
    p result
elsif (n[0]-n[1]).abs==1
    result=1
       for i in 1..n[0]
           result*=i
           result%=10**9+7
       end
       result%=10**9+7
       p result
elsif (n[0]-n[1]).abs>1
    p 0
end


use std::io::*;
const MOD: usize = 1_000_000_007;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let mut n: usize = itr.next().unwrap().parse().unwrap();
    let mut m: usize = itr.next().unwrap().parse().unwrap();
    if n < m {
        std::mem::swap(&mut n, &mut m);
    }
    if n - m > 1 {
        println!("0");
    } else {
        let mut ans = 1;
        for i in 2..m + 1 {
            ans = ans * i % MOD * i % MOD;
        }
        for i in m + 1..n + 1 {
            ans = ans * i % MOD;
        }
        if n == m {
            ans = ans * 2 % MOD;
        }
        println!("{}", ans);
    }
}


macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    const P: i64 = 1000000007;
    const L: usize = 100010;

    let mut f: Vec<i64> = vec![0; L];

    f[0] = 1;
    f[1] = 1;
    for i in 2..L {
        f[i] = (f[i-1] * (i) as i64) % P;
    }

    let (n, m) = get!(i64, i64);
    if (n-m).abs() > 1 {
        println!(0);
        return;
    }
    if n == m {
        println!("{}", f[n as usize] * f[m as usize] % P * 2 % P);
    } else {
        println!("{}", f[n as usize] * f[m as usize] % P);
    }
}


use std::io;
use std::str::FromStr;
use std::cmp::{max,min};

static MOD: u64 = 1_000_000_007;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (n, m) = input_tuple();
    let mut ans = 1;
    if n > m + 1 || m > n + 1 {
        println!("0");
        return;
    }

    for i in 1..max(n+1,m+1) {
        ans *= i;
        ans %= MOD;
        if i == min(n, m) {
            ans *= ans;
            ans %= MOD;
        }
    }
    if n == m {
        println!("{}", ans * 2 % MOD);
    } else {
        println!("{}", ans);
    }

}


use proconio::input;
use std::cmp::{min, max};

fn main() {
    input! {
        m: usize,
        n: usize,
    }

    let div = 1000000007;
    let mut ans = 0;
    match max(m, n) - min(m, n) {
        0 => {
            // 差がないとき
            ans = ((power(m) % div) * (power(n) % div) % div) * 2;
        },
        1 => {
            // 差が1の時
            ans = (power(m) % div) * (power(n) % div) % div;
        },
        _ => {},
    }
    println!("{}", ans % div);
}

fn power(x: usize) -> usize {
    let mut ans = 1;
    for i in 1..=x {
        ans *= i;
    }
    ans
}


use proconio::input;
use std::cmp::{min, max};

fn main() {
    input! {
        m: i128,
        n: i128,
    }

    let mut ans = 0;
    match max(m, n) - min(m, n) {
        0 => {
            // 差がないとき
            ans = power(m) * power(n) * 2;
        },
        1 => {
            // 差が1の時
            ans = power(m) * power(n);
        },
        _ => {},
    }
    println!("{}", ans % 1000000007);
}

fn power(x: i128) -> i128 {
    let mut ans = 1;
    for i in 1..=x {
        ans *= i;
    }
    ans
}


use proconio::input;
use std::cmp::{min, max};

fn main() {
    input! {
        m: usize,
        n: usize,
    }

    let mut ans = 0;
    match max(m, n) - min(m, n) {
        0 => {
            // 差がないとき
            ans = power(m) * power(n) * 2;
        },
        1 => {
            // 差が1の時
            ans = power(m) * power(n);
        },
        _ => {},
    }
    println!("{}", ans % 1000000007);
}

fn power(x: usize) -> usize {
    let mut ans = 1;
    for i in 1..=x {
        ans *= i;
    }
    ans
}


let i=readLine()!.characters.split(" ").map{Int(String($0))!},m=Int(1e9+7)
func f(x:Int)->Int{return (1...x).reduce(1){$0*$1%m}}
print(f(i[0])*f(i[1])*max(2-abs(i[0]-i[1]),0)%m)


func factorial(x:Int)->Int{return (1...x).reduce(1){$0*$1%1000000007}}
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, M) = (input[0], input[1])
print(factorial(N)*factorial(M)*(N==M ? 2:abs(N-M)<2 ?1:0)%1000000007)


let i=readLine()!.characters.split(" ").map{Int(String($0))!},m=1000000007
func f(x:Int)->Int{return (1...x).reduce(1){$0*$1%m}}
print(f(i[0])*f(i[1])*max(2-abs(i[0]-i[1]),0)%m)


let i=readLine()!.characters.split(" ").map{Int(String($0))!},m=Int(1e+9)
func f(x:Int)->Int{return (1...x).reduce(1){$0*$1%m}}
print(f(i[0])*f(i[1])*max(2-abs(i[0]-i[1]),0)%m)


let i=readLine()!.characters.split(" ").map{Int(String($0))!},m=1000000007
func f(x:Int)->Int{return (1...x).reduce(1){$0*$1%m}
print(f(i[0])*f(i[1])*max(2-abs(i[0]-i[1]),0)%m)


{
  const main = (input: string): void | string | number => {
    const r = _reader(input)
    const [n, m] = r.nn()

    if (Math.abs(m - n) >= 2) {
      return 0
    }
    let res = _product(m, _mod, _product(n, _mod, 1))

    if (m === n) {
      res *= 2
    }
    return res % _mod
  }
  const _mod = 10 ** 9 + 7
  const _range = (n: number) => Array.from(Array(n).keys())
  const _product = (n: number, mod, start: number) =>
    _range(n).reduce((p, c) => (p * (c + 1)) % mod, start)

  const _reader = (str: string, i = 0) => {
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')
    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  const _getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const _res = main(_getInput())

  if (typeof _res === 'number' || typeof _res === 'string') console.log(_res)
}


{
  const main = (input: string): void | string | number => {
    const r = _reader(input)
    const [n, m] = r.nn()

    if (Math.abs(m - n) > 2) {
      return 0
    }
    let res = _product(m, _mod, _product(n, _mod, 1))

    if (m === n) {
      res *= 2
    }
    return res % _mod
  }
  const _mod = 10 ** 9 + 7
  const _range = (n: number) => Array.from(Array(n).keys())
  const _product = (n: number, mod, start: number) =>
    _range(n).reduce((p, c) => (p * (c + 1)) % mod, start)

  const _reader = (str: string, i = 0) => {
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')
    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  const _getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const _res = main(_getInput())

  if (typeof _res === 'number' || typeof _res === 'string') console.log(_res)
}


S = input()

if S == "Sunny":
    print("Cloudy")
elif S == "Cloudy":
    print("Rainy")
else:
    print("Sunny")


import sys

#+++++

def main():
	a= ['Sunny', 'Cloudy', 'Rainy']
	a=a+a
	today = input()
	for i,w in enumerate(a):
		if w==today:
			print(a[i+1])
			return

#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline

	ret = main()
	if ret is not None:
		print(ret)


a = input()
if (a == "Sunny"):
  print("Cloudy")
elif (a == "Cloudy"):
  print("Rainy")
elif (a == "Rainy"):
  print("Sunny")


s=input()

if s=="Sunny":
  print("Cloudy")
elif s=="Cloudy":
  print("Rainy")
elif s=="Rainy":
  print("Sunny)


s=str(input())
if s=='S':
  print('C')
elif s=='C':
  print('R')
else:
  print('S')


n = int(input())
s = input()

def z_algorythm(s):
    n = len(s)
    LCP = [0]*n
    c = 0
    for i in range(1, n):
        if i + LCP[i-c] < c + LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and s[j] == s[i+j]:
                j += 1
                LCP[i] = j
                c = i
    LCP[0] = n
    return LCP

ans = 0
for i in range(n):
    LCP = z_algorythm(s[i:])
    for j, len in enumerate(LCP):
        tmp = min(len, j)
        ans = max(ans, tmp)
print(ans)


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * 課題C1
 *
 * @author ken2
 */
public class Main {

	/** 天気：晴れ */
	private static final String WATHER_SUNNY = "Sunny";
	/** 天気：曇り */
	private static final String WATHER_CLOUDY = "Cloudy";
	/** 天気：飴 */
	private static final String WATHER_RAINY = "Rainy";

	/**
	 * メイン処理

	 * @param args 起動引数
	 */
	public static void main(String[] args) {

		// 標準入力から今日の天気を取得
		String weather = scanTodayWeather(System.in);

		// 標準出力へ明日の天気を出力
		if (weather.equals(WATHER_SUNNY)) {
			System.out.println(WATHER_CLOUDY); // Sunny→Cloudy
		}
		if (weather.equals(WATHER_CLOUDY)) {
			System.out.println(WATHER_RAINY); // Cloudy→Rainy
		}
		if (weather.equals(WATHER_RAINY)) {
			System.out.println(WATHER_SUNNY); // Rainy→Sunny
		}
	}

	/**
	 * 今日の天気を取得
	 *
	 * @param in 入力ストリーム
	 * @return 今日の天気
	 */
	private static String scanTodayWeather(InputStream in) {
		InputStreamReader isr = new InputStreamReader(in);
		BufferedReader br = new BufferedReader(isr);
		String weather = null;
		try {
			weather = br.readLine();
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return weather;
	}
}


import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String a = sc.next();
        if(a.equals("Sunny")) p("Cloudy");
        else if(a.equals("Cloudy")) p("Rainy");
        else p("Sunny");
    }
    public static String stringCopy(String str) {
        StringBuilder builder = new StringBuilder();
        builder.append(str.toCharArray());
        return builder.toString();
    }
    public static <T> void p(T element) {
	System.out.println(element);
    }
    public static <T> void pp(T element) {
        System.out.print(element);
        }
    public static int min(int a, int b, int c) {
	int min = Math.min(a,b);
	min = Math.min(min,c);
	return min;
    }
    public static int max(int a, int b,int c) {
	int max= Math.max(a,b);
	max = Math.max(max,c);
        return max;
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Throwable {
		MyScanner sc = new MyScanner();
		String s = sc.nextString();

		switch (s) {
		case "Sunny":
			System.out.println("Cloudy");
			break;
		case "Cloudy":
			System.out.println("Rainy");
			break;
		case "Rainy":
			System.out.println("Sunny");
			break;
		default:
			break;
		}
	}

	static class MyScanner {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		public String nextString() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(nextString());
		}

		public String[] nextStringArr() throws IOException {
			return nextString().split(" ");
		}

		public Integer[] nextIntArr() throws IOException {
			String[] strArr = nextStringArr();
			Integer[] intArr = new Integer[strArr.length];
			for (int i = 0; i < strArr.length; i++) {
				intArr[i] = Integer.parseInt(strArr[i]);
			}
			return intArr;
		}
	}

}


import java.util.*;
public class Main {

    public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
        String st = sc.next();
        String Sunny, Cloudy, Rainy;
        if(st.equals(Sunny)){
            System.out.print("Cloudy");
        }else if(st.equals(Cloudy)){
            System.out.print("Rainy");
        }else{
            System.out.print("Sunny");
        }
    }
}


import java.util.*;
public class main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next();
		if(a.equals("Sunny")) {
			System.out.print("Cloudy");
		}
		if(a.equals("Cloudy")) {
			System.out.print("Rainy");
		}
		if(a.equals("Rainy")) {
			System.out.print("Sunny");
		}
	}

}


import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String S = sc.next();
      String Q[] = {"Sunny","Cloudy","Rainy"};
      int P = Arrays.asList(Q).indexOf(S);
      if(P==2){
        System.out.println("sunny");
      }else{
        System.out.println(Q[P+1]);
      }
    }
}


#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
using namespace std;
typedef long long LL;
typedef double db;
//char buf[1<<24],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
	if (x< 0) putchar('-'),x=-x;
	if (x>=10) print(x/10);
	putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
char s[N];
int main ()
{
	// freopen (".in","r",stdin);
	// freopen (".out","w",stdout);
	scanf ("%s",s+1);
	if (s[1]=='S') puts("Cloudy");
	else if (s[1]=='C') puts("Rainy");
	else puts("Sunny");

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
#define abs(a) (a>0?a:(-(a)))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
char s[1000];
int main(){
	scanf("%s",s);
	if (s[0]=='S') printf("Cloudy");else
	if (s[0]=='C') printf("Rainy");else
		printf("Sunny");
	return 0;
}


#include<stdio.h>
#include<string.h>
int main(void)
{
  char sun[]="Sunny";
  char rei[]="Rainy";
  char cro[]="Cloudy";
  char s[100000];
  scanf("%s",s);
  if(strcmp(s,sun)==0){
	printf("%s\n",cro);
  }
  else if(strcmp(s,rei)==0){
    printf("%s\n",sun);
  }
  else{
    printf("%s\n",rei);
  }
  return 0;
}


#include<bits/stdc++.h>
int main(){
string s;
  cin>>s;
  s=="Sunny"?cout<<"Cloudy":(s=="Cloudy"?cout<<"Rainy":cout<<"Sunny");
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    string s;
    cin >> s;
    if (s == "Sunny")
        cout << "Cloudy" << endl;
    else if (s == "Cloudy") {
        cout << "Rainy" << ednl;
    } else {
        cout << "Sunny" << endl;
    }
    return 0;
}