fun main() {
    val (y, b, r) = readLine()!!.split(" ")
    val m = minOf(y.toInt(), b.toInt() - 1, r.toInt() - 2)
    println(m * 3 + 3)
}

data class Ornament(val ornament: Int, val offset: Int) {
    fun get() = ornament - offset
}

// red > blue > yellow exactly 1 is great christmas ornament
class ChristmasOrnament {
    var totalRed: Int = 0
    var totalBlue: Int = 0
    var totalYellow: Int = 0

    fun input() {
        val args = mutableListOf<Ornament>()
        val ornaments = readLine()!!.split(" ").map { it.toInt() }
        totalYellow = ornaments[0]
        totalBlue = ornaments[1]
        totalRed = ornaments[2]
        args.add(Ornament(totalRed, 0))
        args.add(Ornament(totalRed, 1))
        args.add(Ornament(totalRed, 2))
        output(args)
    }

    fun output(args: List<Any>) {
        val ornaments = args.map { it as Ornament }
        val christmasOrnaments = decrease(ornaments[0], ornaments[1], ornaments[2])
        val totalOrnaments = christmasOrnaments.reduce { acc, i -> acc + i }
        println(totalOrnaments)
    }

    private fun decrease(red: Ornament, blue: Ornament, yellow: Ornament): List<Int> {
        return if (blue.get() <= totalBlue && yellow.get() <= totalYellow) listOf(red.get(), blue.get(), yellow.get())
        else decrease(
            Ornament(red.get() - 1, offset = 0),
            Ornament(red.get() - 1, offset = 1),
            Ornament(red.get() - 1, offset = 2)
        )
    }
}

fun main() {
    ChristmasOrnament().input()
}

import java.util.*
import kotlin.math.min

fun main(args : Array<String>) {
    val reader = Scanner(System.`in`)

    var y:Int
    var b:Int
    var r:Int
    var min:Int
    var result:Int

    y=reader.nextInt()
    b=reader.nextInt()
    r=reader.nextInt()

    min= minOf(y,b,r)
    result= when (min) {
        r -> r+(r-1)+(r-2)
        b -> (b-1)+b+(b+1)
        else -> { // Note the block
           if(r-y>1){
               y+(y+1)+(y+2)
           }else{
               (y-1)+(y)+(y+1)
           }
        }
    }

    println(result)

}

fun main() {
    var str = readLine().toString()
    var parts = str.split(" ").toTypedArray()
    var y = parts[0].toInt()
    var b = parts[1].toInt()
    var r = parts[2].toInt()
    var m1 = b-y-1
    var m2 = r-y-2
    var orn = y*3 + 3
    if ((m1 < 0) || (m2 < 0)) {
        if (m1 <= m2) {
            orn += m1*3
        } else {
            orn += m2*3
        }
    }

    print(orn)
}

fun main() {
    val (a, b, c) = readLine()!!.split(" ").map(String::toInt)
    val d = minOf(a, b - 1, c - 2)
    println(d * 3 + 3)
}

import java.util.Scanner

fun main(args: Array<String>) {

    val read=Scanner(System.`in`)
    var a=read.nextInt()
    var b=read.nextInt()
    var c=read.nextInt()

    while(true) {

        if((a+1<=b) and (a+2<=c))
        {
            b=a+1
            println("${3*b}")
            return
        }
        a--
    }
}

fun main(){
    fun readLn() = readLine()!!
    fun readStrings(delim: Char = ' ') = readLn().split(delim)
    fun readInts() = readStrings().map { it.toInt() }

    val (y,b,r) = readInts()

    println(3+3*Math.min(y,Math.min(b-1,r-2)))

}

fun main() {
    val balls = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    balls[1]--
    balls[2] -= 2
    var min = balls.min()!!
    println(min * 3 + 3)

}

import kotlin.math.min

fun main() {
    print( ProblemB(ProblemB.readInput()).solve() )
}

class ProblemB (triple: Triple<Int, Int, Int>) {

    val yellow  = triple.first
    val blue    = triple.second
    val red     = triple.third

    companion object {
        fun readInput() : Triple<Int, Int, Int> {
            val line = readLine()
            val values : List<Int> = line!!.split(" ").map { it.toInt() }
            return Triple(values[0], values[1], values[2])
        }
    }

    fun solve() : Int {
        return solution(min(yellow + 1, min(blue, red - 1) ))
    }

    private fun solution(value: Int): Int {
        return if (yellow >= value - 1 && red > value) {
            value * 3
        } else
            solution(value - 1)
    }
}

import kotlin.math.min

fun main() {
    val (y, b, r) = readLine()!!.split(' ').map(String::toInt)
    println(3 * min(min(b, y + 1), r - 1))
}

import java.util.*

fun main(args: Array<String>) {
    val input = Scanner(System.`in`)
    val yellow = input.nextInt()
    val blue = input.nextInt()
    val red = input.nextInt()
    if (blue <= yellow && blue < red) {
        val sum = blue + 1 + blue + blue - 1
        println(sum)
    } else if (yellow < blue && yellow < red) {
        val diff = red - yellow
        if (diff >= 2) {
            val sum = yellow + yellow + 1 + yellow + 2
            println(sum)
        } else {
            val sum = yellow - 1 + yellow + yellow + 1
            println(sum)
        }
    } else {
        val sum = red + red - 1 + red - 2
        println(sum)
    }
}

fun  main( args :  Array<String>) {

    val str= readLine()!!

    val ar = str.split(" ")
    val y = ar[0].toInt()
    val b = ar[1].toInt()
    val r = ar[2].toInt()
    val n = minOf(y + 1, b, r - 1)
    println(n*3)
    }

fun main() {
    val line = readLine()!!.split(" ").mapIndexed{ind,n -> n.toInt()*3+(3-3*ind) }.min()
    println(line)
}

fun main() {
    println( readLine()!!.split(" ").mapIndexed{ind,n -> n.toInt()*3+(3-3*ind) }.min())
}

fun main() {
    val (y, b, r) = readLine()!!.split(" ").map { it.toInt() }
    println(listOf(y, b - 1, r - 2).min()!! * 3 + 3)
}

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

val reader = BufferedReader(InputStreamReader(System.`in`))
var tokenizer = StringTokenizer("")

val token: String
    get() {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer.nextToken()
    }

fun readInt() = token.toInt()

fun main() {
    PrintWriter(System.out).use { writer ->
        writer.solve()
    }
}

fun PrintWriter.solve() {
    val y = readInt()
    val b = readInt()
    val r = readInt()
    println(listOf(y, b - 1, r - 2).min()!! * 3 + 3)
}

import java.util.*
import kotlin.math.min

fun main() {
    Scanner(System.`in`).use { scanner ->
        println(min(min(scanner.nextInt(), scanner.nextInt() - 1), scanner.nextInt() - 2) * 3 + 3)
    }
}

import java.util.*
import kotlin.math.min

fun main() {
    val scanner = Scanner(System.`in`)
    println(min(min(scanner.nextInt(), scanner.nextInt() - 1), scanner.nextInt() - 2) * 3 + 3)
}

import java.util.*
import kotlin.math.min

fun main() {
    Scanner(System.`in`).use { scanner ->
        val y = scanner.nextInt()
        val b = scanner.nextInt() - 1
        val r = scanner.nextInt() - 2
        val min = min(min(y, b), r)
        println(min * 3 + 3)
    }
}

import java.util.Scanner

fun main(args: Array<String>) {
    var scan = Scanner(System.`in`)
    var y: Int
    var b: Int
    var r: Int
    var n: Int = 0
    y = scan.nextInt()
    b = scan.nextInt()
    r = scan.nextInt()
    var min = if (y <= b) -1 else -2
    if (min ==-1)
    	min = if (y <= r) -1 else -3
    else
    	min = if (b <= r) -2 else -3

    if (min == -3)        //red is minimum
    	n = (r - 1) * 3
    else if (min == -2){  //blue is minimum
        if (b == r){
            b = r - 1
            n = b * 3
        }
        else
        	n = b * 3
    }
    else if (min == -1){  //yellow is minimum
        if ((r - y) >= 2){
            if ((b - y) >= 1)
            	n = (y + 1) * 3
            else{
                y = b - 1
                n = (y + 1) * 3
            }
        }
        else{
            y = r -2
            n = (y + 1) * 3
        }
    }

    println (n)

}

fun main(args: Array<String>) {
    val ints = readLine()?.split(" ")?.map(String::toInt) ?: return
    val minStart = ints.mapIndexed { index, int -> int - index }.min()!!
    val result = minStart * 3 + 3
    print(result)
}

import java.util.*

fun main() = with(Scanner(System.`in`))  {
    val min = Array(3) { nextInt() }.mapIndexed { index, int -> int - index }.min()
    if (min != null) {
        print(min * 3 + 3)
    }
}

import java.util.*
import kotlin.math.min

fun main(args: Array<String>) = with(Scanner(System.`in`)) {

    val line = nextLine().split(' ')
    val y = line[0].toInt()
    val b = line[1].toInt()
    val r = line[2].toInt()

    val min = min(y, min(b, r))
    val secondMin: Int
    var printVal = 0
    when (min) {
        r -> println(3 * r - 3)
        b -> {
            secondMin = min(y, r)
            when (secondMin) {
                r -> printVal =
                    if (secondMin - min < 1)
                        r - 1
                    else
                        b
                y -> printVal = b
            }
            println(printVal * 3)
        }
        y -> {
            secondMin = min(b, r)
            when (secondMin) {
                r -> printVal =
                    if (secondMin - min < 2)
                        r - 2
                    else
                        y
                b -> printVal =
                    if (secondMin - min < 1)
                        b - 1
                    else
                        y
            }
            println(printVal * 3 + 3)
        }

    }
}

import kotlin.math.min

fun main() {
    val (a, b, c) = readLine()!!.split(" ").map{ it.toInt() }
    val answer = min(min(a, b - 1), c - 2) * 3 + 3
    println(answer)
}

fun main(args: Array<String>) {

    val parts = readLine()!!.toString().split(" ")
    val v1 : Int =parts.get(0).toInt()
    val v2 : Int= parts.get(1).toInt()
    val v3 : Int = parts.get(2).toInt()

    var res : Int = 0;

    if(v1+1 <= v2 && v1+2<=v3){
        res = v1 + v1+1 + v1+2
        println("$res")
    }else {
        if(v2+1 <= v3 && v2-1<=v1){
            res = v2-1 + v2 + v2+1
            println("$res")
        }else {
            res = v3-2+v3-1+v3
            println("$res")
        }
    }
}

fun main(args: Array<String>) {
    val (y, b, r) = readLine()!!.split(" ").map { it.toInt() }
    val my = minOf(y, b - 1, r - 2)
    println(3 * my + 3)
}

private fun readLn() = readLine()!!
private fun readStrings() = readLn().split(" ")
private fun readInt() = readLn().toInt()
private fun readInts() = readStrings().map { it.toInt() }

fun main(){

    val(y, b, r) = readInts()

    var ans : Int = 0

    if( y+1 <= b && y+2 <= r && 3*y+3 > ans ) ans = 3*y+3

    if( b-1 <= y && b+1 <= r && 3*b > ans ) ans = 3*b

    if( r-2 <= y && r-1 <= b && 3*r-3 > ans ) ans = 3*r-3

    println("$ans")

}

fun main() {
    var ybr = readLine()!!.split(' ').map { it.toInt() }

    println(MaxSum(ybr))
}

fun MaxSum(values: List<Int>): Int {
    var middle = values[1]
    while (middle - 1 > values.first() || middle + 1 > values.last())
        middle -= 1

    return 3 * middle
}

import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)

    var yellow = 1
    var blue = 2
    var red = 3

    yellow = scanner.nextInt()
    blue = scanner.nextInt()
    red = scanner.nextInt()

    val summ = 0

    while (yellow != blue - 1 || yellow != red - 2 && blue != red - 1) {

        if (yellow >= blue)
            yellow = blue - 1
        else if (yellow < blue)
            blue = yellow + 1

        if (blue >= red)
            blue = red - 1
        else if (blue < red)
            red = blue + 1

    }

    print(yellow + blue + red)
}

import java.io.*
import java.math.*
import java.text.*
import java.util.*
import java.util.regex.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    val x = scan.nextInt()
    val y = scan.nextInt()
    val z = scan.nextInt()
    var ans= y
    val flag = true
    while(flag)
    {
     if(ans+1<=z&&ans-1<=x)
     {
        print(ans*3)
        break
     }
     ans=ans-1
    }

}

fun main(args: Array<String>) {
    val inp = readLine()!!.split(" ").map(String::toInt)
    val x = inp[0]
    val y = inp[1]
    val z = inp[2]

    var ans= y
    while(ans>0)
    {
     if(ans+1<=z&&ans-1<=x)
     {
        print(ans*3)
        break
     }
     ans=ans-1
    }

}

fun main() {
    val inputs = readLine()!!.split(" ").map { it.toInt() }
    val (yellow, blue, red) = inputs
    var result = 0

    inputs.asReversed().forEachIndexed { index, input ->
        when (index) {
            0 -> if (input - 1 <= blue && input - 2 <= yellow)
                result = input * 3 - 3
            1 -> if (input + 1 <= red && input - 1 <= yellow)
                result = input * 3
            2 -> if (input + 1 <= blue && input + 2 <= red)
                result = input * 3 + 3
        }

        if (result > 0)
            return@forEachIndexed
    }

    print(result)
}

fun main() {
    val inputs = readLine()!!.split(" ")
    val (yellow, blue, red) = inputs.map { it.toInt() }
    var result = 0

    inputs.asReversed().map { it.toInt() }.forEachIndexed { index, input ->
        when (index) {
            0 -> {
                if (input - 1 <= blue && input - 2 <= yellow) {
                    result = input * 3 - 3
                    return@forEachIndexed
                }
            }
            1 -> {
                if (input + 1 <= red && input - 1 <= yellow) {
                    result = input * 3
                    return@forEachIndexed
                }
            }
            2 -> {
                if (input + 1 <= blue && input + 2 <= red) {
                    result = input * 3 + 3
                    return@forEachIndexed
                }
            }
        }
    }

    print(result)
}

fun main() {
    val inputs = readLine()!!.split(" ")
    val (yellow, blue, red) = inputs.map { it.toInt() }
    var result = 0

    inputs.forEachIndexed { index, input ->
        val _input = input.toInt()
        when (index) {
            2 -> {
                if (_input - 1 <= blue && _input - 2 <= yellow) {
                    result = _input * 3 - 3
                    return@forEachIndexed
                }
            }
            1 -> {
                if (_input + 1 <= red && _input - 1 <= yellow) {
                    result = _input * 3
                    return@forEachIndexed
                }
            }
            0 -> {
                if (_input + 1 <= blue && _input + 2 <= red) {
                    result = _input * 3 + 3
                    return@forEachIndexed
                }
            }
        }
    }

    print(result)
}

fun main(args: Array<String>) {

        val input = readLine()!!
        val values = input.split(" ")
        println(Christmas(values[0].toInt(), values[1].toInt(), values[2].toInt()))

}

enum class Color {Blue,Red,Yellow}

fun Christmas(yellowcolor:Int,bluecolor:Int,redcolor:Int):Int
{
    if(yellowcolor==bluecolor && bluecolor==redcolor)
        return (yellowcolor-1)+yellowcolor+(yellowcolor-2)

    return when(if (yellowcolor <= bluecolor && yellowcolor <= redcolor)
        Color.Yellow
    else if (bluecolor <= redcolor && bluecolor <= yellowcolor)
        Color.Blue
    else
        Color.Red){
        Color.Yellow -> if(yellowcolor==bluecolor)
                             yellowcolor+(yellowcolor+1)+(yellowcolor-1)
                        else if (redcolor==bluecolor && (redcolor+bluecolor)-(yellowcolor*2)<3)
                             yellowcolor+(yellowcolor+1)+(yellowcolor-1)
                        else if (yellowcolor==redcolor)
                             yellowcolor+(yellowcolor-2)+(yellowcolor-1)
                        else if (bluecolor>redcolor && redcolor-yellowcolor==1)
            yellowcolor+(yellowcolor+1)+(yellowcolor-1)

        else if(redcolor>bluecolor || redcolor==bluecolor ||(bluecolor>redcolor && (redcolor+bluecolor)-(yellowcolor*2)>3))
                            yellowcolor+(yellowcolor+1)+(yellowcolor+2)

                        else
                            yellowcolor+(yellowcolor+1)+(yellowcolor-1)

        Color.Blue-> if(bluecolor==redcolor)
            (bluecolor-2)+bluecolor+(bluecolor-1)
            else
                        (bluecolor+1)+bluecolor+(bluecolor-1)
        else -> redcolor+(redcolor-2)+(redcolor-1)
    }

}

fun main() {
    val inp = readLine()
    if(inp != null) {
        val arr = inp.split(' ').map { e -> Integer.parseInt(e) }
        var a = arr[0]
        var b = arr[1]
        var c = arr[2]

        if(b >= c)
            b = c-1

        if(a >= b)
            a = b - 1

        println(a*3 + 3)
    }
}

fun main() {
    val base = listOf(0, 1, 2)
    val baseSum = base.sum()
    val numbers = readLine()?.split(' ')?.map { it.toInt() } ?: base
    val low = numbers.zip(base, Int::minus).min() ?: - baseSum
    print(low * base.size + baseSum)
}

fun main() {
    val base = listOf(0, 1, 2)
    val baseSum = base.sum()
    val numbers = readLine()?.split(' ')?.map { it -> it.toInt() } ?: base
    val low = numbers.zip(base, Int::minus).min() ?: - baseSum
    print(low * base.size + baseSum)
}

fun main()
{
    val(a,b,c)=readLine()!!.split(' ').map(String::toInt)
    print(3*minOf(a+1,b,c-1))
}

fun main() {
    var (y, b, r) = readLine()!!.split(" ").map { it.toInt() }
    if (b >= r)
        b = r - 1
    if (y >= b)
        y = b - 1
    b = y + 1
    r = b + 1
    println("${y + b + r}")
}

fun main()
{
    val (a:Int,b:Int,c:Int)= readLine()!!.split(' ').map(String::toInt)
    println("${3*minOf(a,b-1,c-2)+3}")
}

fun main() {
    val line = readLine()!!.split(" ")
    val y = line[0].toInt()
    val b = line[1].toInt()
    val r = line[2].toInt()
    val min = minOf(y, b, r)
    if (min == r) {
        println(3 * r - 3)
        return
    }

    if (min == b) {
        println(3 * (b))
        return
    }

    if (min == y) {
        if (r > b) {
            println((3 * y) + 3)
        } else {
            if (r == y + 1) {
                println(3 * (y - 1) + 3)
            } else {
                println((3 * y) + 3)
            }
        }
    }
}

fun main() {
    val (y, b, r) = readInts(3).toList()
    if (b >= r - 1) {
        if (y >= r - 2) {
            println((r - 1) * 3)
            return
        }
        println((y + 1) * 3)
        return
    }
    if (y >= b - 1) {
        println(b * 3)
        return
    }
    println((y + 1) * 3)
}

private fun isWhiteSpace(c: Char) = c in " \r\n\t"

private fun readString() = generateSequence { System.`in`.read().toChar() }
    .dropWhile { isWhiteSpace(it) }
    .takeWhile { !isWhiteSpace(it) }
    .joinToString("")

private fun readInt() = readString().toInt()
private fun readInts(n: Int) = generateSequence { readInt() }.take(n)

import java.util.Scanner
import kotlin.math.min

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    //arrayOf("8","13","9")
    val yellowOrnaments = sc.nextInt()
    val blueOrnaments = sc.nextInt()
    val redOrnaments = sc.nextInt()

    println(3 * min(yellowOrnaments, min(blueOrnaments, redOrnaments - 1) - 1) + 3)
}

import com.sun.org.apache.xpath.internal.operations.Bool
import jdk.nashorn.internal.runtime.ScriptingFunctions.readLine
import java.util.Scanner
fun max(a:Int,b:Int):Int
{
    if(a<=b)return a
    else return b
}
fun main(args: Array<String>)
{
    val read= Scanner(System.`in`)
   var c=Array(4,{it ->0})
    var maxn:Int
    maxn=1000000
    for(i in 1..3){
        c[i]=read.nextInt()
        c[i]=c[i]-i+1
        maxn  =max(c[i],maxn)
    }

    println(3*maxn+3)
}

//package b

import java.io.PrintWriter
import java.util.*

fun solve() {
    val (y, b, r) = na()
    val u = Math.min(Math.min(y+1, b), r-1)
    out.println(u*3)
}

val out = PrintWriter(System.out)

fun main(args: Array<String>) {
    solve()
    out.flush()
}

fun nline() = readLine()!!
fun ni() = nline().toInt()
fun nl() = nline().toLong()
fun nd() = nline().toDouble()
fun nas() = nline().split(" ")
fun na() = nas().map { it.toInt() }
fun nal() = nas().map { it.toLong() }

fun tr(x: Any) = System.err.println(x)
fun tr(x: IntArray) = System.err.println(Arrays.toString(x))
fun tr(x: Array<Any>) = System.err.println(Arrays.deepToString(x))

fun main() {
    var a = readLine()!!.split(' ')!!.map(String::toInt)
    println(minOf(a[0]+1,a[1],a[2]-1)*3)
}

fun readLines(): List<String> {
    val amount = readLine()?.toInt()!!
    return (0 until amount).map { readLine()!! }
}

fun main() {
    val (y, b, r) = readLine()!!.split(" ").map { it.toInt() }
//    val (y, b, r) = "8 13 9".split(" ").map { it.toInt() }
    // 4 5 6
    val py = Math.min(y, Math.min(b-1, r-2))
    println(py + py + py + 1 + 2)
}

fun main(args: Array<String>){
    var i = 2
    var min = Int.MAX_VALUE
    val nums = readLine()!!.split(" ").map { s -> s.toInt() }
    if(nums[2]<min)
        min = nums[2]
    if(nums[1]<min-1){
        min = nums[1]
        i = 1
    }
    if(nums[0]<min-1){
        min = nums[0]
        i = 0
    }
    print("${if(i==0)3*(min+1) else if(i==1) 3*min else 3*(min-1)}")
}

fun main(args: Array<String>){
var (Y,B,R)=readLine()!!.split(" ")
var y=Y.toInt()
var b=B.toInt()
var r=R.toInt()
b=b+1
y=y+2
var ans=kotlin.math.min(b,y)
ans=kotlin.math.min(ans,r)
println((ans*3-3))
}

// y < b < r
// y = (b - 1) = (r - 2)
fun main(args: Array<String>) {
    val (y, b, r) = readLine()!!.split(' ').map(String::toInt)

    var rMax = r
    if (b < (rMax - 1)) {
        rMax = b + 1
    }

    if (y < (rMax - 2)) {
        rMax = y + 2
    }

    println(rMax * 3 - 3)

}

fun main() {
    val (y, b, r) = readLine()!!.split(" ").map { it.toInt() }
    val my = minOf(y, b - 1, r - 2)
    println(3 * my + 3)
}

fun main() {
    val (y,b,r) = readLine()!!.split(" ").map { it.toInt() }
    val res = minOf(y, b-1, r-2)
    println(3*res+3)
}

import kotlin.math.min
fun main(args: Array<String>) {
    val (y, b, r) = readLine()!!.split(' ').map(String::toInt)
    println(min(y + 2, min(b + 1, r)) * 3 - 3)
}

import java.util.*;
import kotlin.math.*;

fun main() {
    val sc = Scanner(System.`in`);
    val a = sc.nextInt() ;
    val b = sc.nextInt() ;
    val c = sc.nextInt() ;
    val ans = minOf(a , b - 1 , c - 2) ;
    println(ans * 3 + 3) ;
}

fun readLn() = readLine()!!
fun readInt() = readLn().toInt()
fun readStrings() = readLn().split(" ")
fun readInts() = readStrings().map { it.toInt() }
fun main() {
    val (y, b, r) = readInts()
    println(3 * listOf(y, b-1, r-2).min()!! + 3)
}

import java.lang.Math.min

fun main() {
    val (y, b, r) = readLine()!!.split(" ").map { it.toInt() }
    val r2 = (y + 2).coerceAtMost((b + 1).coerceAtMost(r))
    val b2 = r2-1
    val y2=b2-1
    println(y2+b2+r2)

}

//package com.happypeople.codeforces.c1091

import java.io.ByteArrayInputStream
import java.io.InputStream
import java.util.*
import kotlin.math.min

fun main(args: Array<String>) {
    try {
        A().run()
    } catch (e: Throwable) {
        A.log("" + e)
    }
}

class A {
    fun run() {
        val sc = Scanner(systemIn())
        val y=sc.nextInt()
        val b=sc.nextInt()
        val r=sc.nextInt()

        // b==y+1
        // r==b+1

        var m=min(b, y+1)
        m=min(m+1, r)
        m=3*m-3
        println("$m")
    }

    companion object {
        var inputStr: String? = null

        fun systemIn(): InputStream {
            if (inputStr != null)
                return ByteArrayInputStream(inputStr!!.toByteArray())
            else
                return System.`in`
        }

        var printLog = false
        fun log(str: String) {
            if (printLog)
                println(str)
        }
    }
}

fun main() {
    val (y, b, r) = readInts()

    val ans = minOf(y+1, b, r-1) * 3

    println(ans)
}

fun readLn() = readLine()!!
fun readInt() = readLn().toInt()
fun readDouble() = readLn().toDouble()
fun readLong() = readLn().toLong()
fun readStrings() = readLn().split(' ')
fun readInts() = readStrings().map { it.toInt() }
fun readDoubles() = readStrings().map { it.toDouble() }
fun readLongs() = readStrings().map { it.toLong() }

class Output {
    private val sb = StringBuilder()
    fun print(o: Any?) { sb.append(o) }
    fun println() { sb.append('\n') }
    fun println(o: Any?) { sb.append(o).append('\n') }
    @JvmName("_print") fun Any?.print() = print(this)
    @JvmName("_println") fun Any?.println() = println(this)
    fun nowPrint() { kotlin.io.print(sb) }
}
inline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }

import kotlin.math.min

fun main() {
    val(y, b, r) = readLine()!!.split(" ").map { it.toInt() }
    val n = min(y, min(b-1, r-2))
    println(3 * n + 3)
}

fun main() {
    println(readLine()!!.split(' ').mapIndexed { index, s -> s.toInt() - index }.min()!!.toInt() * 3 + 3)
}

fun main() {
   val input = readLine()?.split(' ') ?: emptyList()
    val y = input[0].toByte()
    val b = input[1].toByte()
    val r = input[2].toByte()

    val b1: Byte = 1
    val b2: Byte = 2
    val b3: Byte = 3

    println(when (minOf(y, b, r)) {
        r -> (r-b2) * b3 + b3
        b -> (b-b1) * b3 + b3
        y -> if (r - y < 2) (y-b1) * b3 + b3 else y * b3 + b3
        else -> -1
    })
}

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

fun main(args: Array<String>) {
    TaskA().solve()
}

abstract class Solver {
    internal val scanner = MyScanner()
    abstract fun solve()
}

class TaskA : Solver() {
    override fun solve() {
        val y = scanner.nextInt()
        val b = scanner.nextInt()
        val r = scanner.nextInt()

        var nr = r
        while (nr-1 > b || nr -2 > y)
            nr--
        System.out.println(nr*3 - 3)
    }
}

internal class MyScanner {
    private val `in` = BufferedReader(InputStreamReader(System.`in`))
    private var buffer: Array<String>? = null
    private var pos = 0

    @Throws(IOException::class)
    fun nextInt(): Int {
        if (buffer == null) {
            buffer = `in`.readLine().split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
            pos = 0
        }
        if (buffer!!.size <= pos) {
            buffer = `in`.readLine().split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
            pos = 0
        }
        pos++
        return Integer.parseInt(buffer!![pos - 1])
    }

    @Throws(IOException::class)
    fun nextLong(): Long {
        if (buffer == null) {
            buffer = `in`.readLine().split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
            pos = 0
        }
        if (buffer!!.size <= pos) {
            buffer = `in`.readLine().split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
            pos = 0
        }
        pos++
        return (buffer!![pos - 1]).toLong()
    }

    @Throws(IOException::class)
    fun nextString(): String {
        if (buffer == null) {
            buffer = `in`.readLine().split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
            pos = 0
        }
        if (buffer!!.size <= pos) {
            buffer = `in`.readLine().split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
            pos = 0
        }
        pos++
        return buffer!![pos - 1]
    }

    @Throws(IOException::class)
    fun getIntList(n: Int): List<Int> {
        val result = mutableListOf<Int>()
        for (i in 0 until n)
            result.add(nextInt())
        return result
    }

    @Throws(IOException::class)
    fun getIntArray(n: Int): IntArray {
        val result = IntArray(n)
        for (i in 0 until n)
            result[i] = nextInt()
        return result
    }

    @Throws(IOException::class)
    fun getLongList(n: Int): List<Long> {
        val result = mutableListOf<Long>()
        for (i in 0 until n)
            result.add(nextLong())
        return result
    }

    @Throws(IOException::class)
    fun getLongArray(n: Int): LongArray {
        val result = LongArray(n)
        for (i in 0 until n)
            result[i] = nextLong()
        return result
    }

    @Throws(IOException::class)
    fun getStringList(n: Int): List<String> {
        val result = mutableListOf<String>()
        for (i in 0 until n)
            result.add(nextString())
        return result
    }

}

import java.util.Scanner

fun main(args: Array<String>) {
   	var score = 6
    val input = Scanner(System.`in`)
    val a = input.nextInt()
    val b = input.nextInt()
    val c = input.nextInt()
    for (i in 2..999){
        if(i <= a && i+1 <= b && i+2 <= c)
        	score = score+3
        else break
    }
    println(score)
}

fun findNumber(y: Int, b: Int, r: Int): Int {

    // all different
    if (y != b && y != r && b != r) {

        val minNum = minOf(y, b, r)
        val maxNum = maxOf(y, b, r)

        when (maxNum) {
            y -> {
                return when (minNum) {
                    b -> (b - 1) + b + (b + 1)
                    else -> (r - 2) + (r - 1) + r
                }
            }
            b -> {
                return when (minNum) {
                    y -> {
                        if (r - y > 2) y + (y + 1) + (y + 2) else (r - 2) + (r - 1) + r
                    }
                    else -> /* r */ (r - 2) + (r - 1) + r
                }
            }
            else /* r */ -> {
                return when (minNum) {
                    y -> y + (y + 1) + (y + 2)
                    else -> /* b */ (b - 1) + b + (b + 1)
                }
            }
        }

    } else {
        if (y == b) {
            return findNumber(b + r, b, r)
        } else if (y == r) {
            return findNumber(y + r, b, r)
        } else {
            // b == r
            return findNumber(y, b + r, r)
        }
    }

}

fun main(args: Array<String>) {
    val (strY, strB, strR) = readLine()!!.split(' ')

    val y = strY.toInt()
    val b = strB.toInt()
    val r = strR.toInt()

    print(findNumber(y, b, r))
}

import java.util.Scanner
fun main(args: Array<String>) {
val reader = Scanner(System.`in`)
    var y:Int = reader.nextInt()
    var b:Int = reader.nextInt()
    var r:Int = reader.nextInt()
    var ans = r
   var t = r
   if(r-1>b)
    {
    ans=(b+b+1)
    t=b
    }
    else
    {
    ans=ans+(r-1)
    t=r-1
    }
    if(t-1>y)
    {
    ans=(3*y)+3
    }
    else
    {
    ans=ans+(t-1)
    }
    println("$ans\n")
}
/*
fun main(args: Array<String>) {
    var t = readLine()!!.toInt()
    var y = readLine()!!.toInt()
    var b = readLine()!!.toInt()
    var r = readLine()!!.toInt()
    var ans = r
    if(r-1>b)
    {
    ans=(b+b+1)
    t=b
    }
    else
    {
    ans=ans+b
    t=r-1
    }
    if(t-1>y)
    {
    ans=(3*y)+1
    }
    else
    {
    ans=ans+y
    }
    println("$ans\n")
}
*/

fun getMin(a: Int, b: Int, c: Int): Int
{
    if (a <= b && a <= c) return a
    if (b <= c) return b
    return c
}

fun main()
{
    val nn = readLine()!!.split(" ").map { it.toInt() }
    val mini = getMin(nn[0], nn[1] - 1, nn[2] - 2) + 1
    println(mini * 3)
}

fun main(args: Array<String>) {
    val inputLine = readLine()!!
    val parts = inputLine.split(' ')

    if (parts.size != 3) {
        throw Exception()
    }

    val yellow = parts[0].toInt()
    val blue = parts[1].toInt()
    val red = parts[2].toInt()

    if (yellow !in 1..100) {
        throw Exception()
    }

    if (blue !in 2..100) {
        throw Exception()
    }

    if (red !in 3..100) {
        throw Exception()
    }

    println(calculate(yellow, blue, red))
}

fun calculate(yellow: Int, blue: Int, red: Int): Int {
    return if (yellow + 2 <= blue + 1 && yellow + 2 <= red) {
        ((yellow + 2) * 3 - 3)
    } else if (blue + 1 <= yellow + 2 && blue + 1 <= red) {
        ((blue + 1) * 3 - 3)
    } else {
        ((red) * 3 - 3)
    }
}

private fun ri() = readLine()!!.toInt()
private fun rli() = readLine()!!.split(" ").map { it.toInt() }

fun main() {
    val (y, b, r) = rli()
    val maxRed = minOf(r, b+1, y+2)
    println(3 * (maxRed - 1))
}

import java.util.*

fun main() {
    val input = Scanner(System.`in`).nextLine().split(" ").map { Integer.parseInt(it) }.toList()

    fun isValid(yellow: Int, blue: Int, red: Int): Boolean {
        return yellow <= input[0] && blue <= input[1] && red <= input[2] && yellow == blue + blue - red
    }

    var yellow = input[0]
    var blue = yellow + 1
    var red = blue + 1

    while (!isValid(yellow, blue, red)) {
        yellow--
        blue--
        red--
    }

    print(yellow + blue + red)
}

import java.util.Scanner
    fun main(args: Array<String>) {
        val sc = Scanner(System.`in`)
        println(Math.min(Math.min(sc.nextInt(), sc.nextInt() - 1), sc.nextInt() - 2) * 3 + 3)
    }

fun main() {
    //val (a, b, c) = readInts()// read integer from the input
    val fl = readLine()!!.split(" ").map { it.toInt() }
    val x: Int
    if(fl[0]+1 < fl[2]-1) x = fl[0]+1
    else x = fl[2]-1
    if(fl[1]<x) println(3*fl[1])
    else println(3*x)

}

import java.util.Scanner
fun main(args:Array<String>){
	val reader = Scanner(System.`in`)
	var t:Int = reader.nextInt()
	var x:Int = reader.nextInt()
	var y:Int = reader.nextInt()
	var ans = 0
	for(i in 0..t){
		if(i+1 <= x && i+2 <= y){
			ans = 3 * i + 3
		}
	}
	println("$ans")
}

fun main(args: Array<String>) {
    val (y, b, r) = readLine()!!.split(" ").map(String::toInt)
    if (r - y <= 2) {
        if (r - b <= 1) {
            print(r * 3 - 3)
        } else {
            print(b * 3)
        }
    } else {
        if (b - y <= 1) {
            print(b * 3)
        } else {
            print(y * 3 + 3)
        }
    }
}

fun main() {
    var (y, b, r) = readLine()!!.split(" ").map { it.toInt() }
    while (y > 0) {
        if (b > y && r > y + 1) {
            println(3 * y + 3)
            break
        }
        y--
    }
}

import kotlin.math.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
  val (y,b,r) = readInts();
val x = min(y, min(b-1, r-2))
  println(x*3+3)
}

fun main() {
    val balls = readLine()!!.split(Regex("\\s+"), 3).map { it.toInt() }
    val min = balls.min()!!

    val max = when (min) {
        1 -> 6
        balls[2] -> 3 * (min - 1)
        else -> 3 * min
    }
    println("$max")
}

import java.util.*;
import kotlin.math.*;

fun main() {
    val sc = Scanner(System.`in`);
    val a = sc.nextInt() ;
    val b = sc.nextInt() ;
    val c = sc.nextInt() ;
    val ans = minOf(a , b - 1 , c - 1) ;
    println(ans * 3 + 3) ;
}

fun main() {
    val s = readLine()!!
    val s2 = s.split(' ')
    var yellows = s2[0].toInt()
    var blues = s2[1].toInt()
    var reds = s2[2].toInt()

    if (yellows >= blues) {
        yellows -= (yellows - blues) + 1
    }
    if (blues != yellows + 1) {
        blues = yellows + 1
    }
    if (blues >= reds) {
        val diff = blues - reds
        blues -= diff + 1
        yellows -= diff + 2
    }
    if (reds != blues + 1) {
        reds = blues + 1
    }
    print(yellows + blues + reds)
}

fun main(args: Array<String>) {
        val input = readLine()!!
        val values = input.split(" ")
        println(Christmas(values[0].toInt(), values[1].toInt(), values[2].toInt()))
}

enum class Color {Blue,Red,Yellow}

fun Christmas(yellowcolor:Int,bluecolor:Int,redcolor:Int):Int
{
    if(yellowcolor==bluecolor && bluecolor==redcolor)
        return (yellowcolor-1)+yellowcolor+(yellowcolor-2)

    return when(if (yellowcolor <= bluecolor && yellowcolor <= redcolor)
        Color.Yellow
    else if (bluecolor <= redcolor && bluecolor <= yellowcolor)
        Color.Blue
    else
        Color.Red){
        Color.Yellow -> if(yellowcolor==bluecolor)
                             yellowcolor+(yellowcolor+1)+(yellowcolor-1)
                        else if (redcolor==bluecolor && (redcolor+bluecolor)-(yellowcolor*2)<3)
                             yellowcolor+(yellowcolor+1)+(yellowcolor-1)

                        else if(redcolor>bluecolor || redcolor==bluecolor ||(bluecolor>redcolor && (redcolor+bluecolor)-(yellowcolor*2)>3))
                            yellowcolor+(yellowcolor+1)+(yellowcolor+2)

                        else
                            yellowcolor+(yellowcolor+1)+(yellowcolor-1)

        Color.Blue-> (bluecolor+1)+bluecolor+(bluecolor-1)
        else -> redcolor+(redcolor-2)+(redcolor-1)
    }

}

import java.util.*
import kotlin.math.min

fun main(args: Array<String>) = with(Scanner(System.`in`)) {

    val line = nextLine().split(' ')
    val y = line[0].toInt()
    val b = line[1].toInt()
    val r = line[2].toInt()

    val min = min(y, min(b, r))
    val secondMin: Int
    var printVal = 0
    when (min) {
        r -> println(3 * r - 3)
        b -> {
            secondMin = min(y, r)
            when (secondMin) {
                r -> printVal =
                    if (secondMin - min < 1)
                        r - 1
                    else
                        b
            }
            println(printVal * 3)
        }
        y -> {
            secondMin = min(b, r)
            when (secondMin) {
                r -> printVal =
                    if (secondMin - min < 2)
                        r - 2
                    else
                        y
                b -> printVal =
                    if (secondMin - min < 1)
                        b - 1
                    else
                        y
            }
            println(printVal * 3 + 3)
        }

    }
}

fun main() {
    var a = readLine()!!.split(' ')!!.map(String::toInt)
    for (i in 0..2) println(a[i])
    println(minOf(a[0]+1,a[1],a[2]-1)*3)
}

import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val yellowOrnaments = sc.nextInt()
    val blueOrnaments = sc.nextInt()

    var redOrnaments = sc.nextInt()

    repeat(redOrnaments - 3) {
        if (blueOrnaments >= redOrnaments - 1 && yellowOrnaments >= redOrnaments - 2) {
            println(redOrnaments - 2 + redOrnaments - 1 + redOrnaments)
        }
        redOrnaments -= 1
    }
    println(6)
}

fun main () {
    val (y, b, r) = readLine()!!.split(' ').map(String::toInt)
    val v = listOf(y, b, r)
    println(v.min()!! * 3)
}

fun main() {
//    val (y, b, r) = readLine()!!.split(" ").map { it.toInt() }
    val (y, b, r) = "8 13 9".split(" ").map { it.toInt() }
    // 4 5 6
    val py = Math.min(y, Math.min(b-1, r-2))
    println(py + py + py + 1 + 2)
}

import java.io.*
import java.math.*
import java.text.*
import java.util.*
import java.util.regex.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    val x = scan.nextInt()
    val y = scan.nextInt()
    val z = scan.nextInt()
    val ans1: Long = 0
    val ans2: Long = 0
    val ans3: Long = 0
    if(y>x &&z>y)
    print((x+1)*3)
    else if(z<y)
    print((z-1)*3)
    else
    print(y*3)

}

fun readInts() : List<Int> = readLine()?.split(" ")?.map { it.toInt() }?.toList() ?: emptyList()

fun s1() {
    val (y, b, r) =  readInts()
    when {
        (r in (y..b) && (r-y <= 2)) || (y in r..b) || b in ((r+1) .. (y-1)) -> {
            println(r + (r-1) + (r-2))
        }
        b in y .. r || r in y .. b -> println(y + (y+1) + (y+2))
        else -> println(b + (b+1) + (b-1))
    }
}

fun main(args: Array<String>) {
    //while (true) { s1() }
    s1()
}

fun main() {
//    println(calc(1, 2, 3) == 6)
//    println(calc(8, 13, 9) == 24)
//    println(calc(13, 3, 6) == 9)
//    println(calc(1, 3, 4) == 6)

    val (y, b, r) = readLine()!!.split(' ').map(String::toInt)
    print(calc(y, b, r))
}

fun calc(y: Int, b: Int, r: Int): Int {
    var y1 = y
    var b1 = b
    var r1 = r

    if (y + 1 == b && b + 1 == r)
        return y + b + r

    if (y >= r)
        y1 = r - 2

    when {
        b >= r -> b1 = r - 1
        b1 + 1 == r -> b1--
        else -> r1 = b1 + 1
    }

    when {
        b >= r -> b1 = r - 1
        b1 + 1 == r -> b1--
        else -> r1 = b1 + 1
    }

    if (y1 >= b1)
        y1 = b1 - 1

    return y1 + b1 + r1
}

import java.util.Arrays;
import java.util.Scanner;

fun main(){
    B()
}

fun B(){
    val scanner=Scanner(System.`in`)
    val y=scanner.nextInt()
    val b=scanner.nextInt()
    val r=scanner.nextInt()
    val max=Math.max(Math.max(y,b),Math.max(b,y))
    val min=Math.min(Math.min(y,b),Math.min(b,y))
    var result=0
    if(min==y){
        result=y*3+3
    }else if(min==b){
        result=b*3
    }else if(min==r){
        result=r*3-3
    }else
    println("${result}")
}

fun main() {
    var ybr = readLine()!!.split(' ').map { it.toInt() }

    println(MaxSum(ybr))
}

fun MaxSum(values: List<Int>): Int {
    var middle = values[values.size / 2]
    while (middle - 1 > values.first() && middle + 1 > values.last())
        middle -= 1

    return 3 * middle
}

import java.util.*

fun main(args : Array<String>) {
    val reader = Scanner(System.`in`)

    var y:Int
    var b:Int
    var r:Int

    var sum:Int
    y=reader.nextInt()
    b=reader.nextInt()
    r=reader.nextInt()

    r=when {
        b>r -> r
        r>b -> b+1
        else ->r
    }
    b=r-1
    y=b-1

    sum=r+b+y

    println(sum)

}

fun main(){
    fun readLn() = readLine()!!
    fun readStrings(delim: Char = ' ') = readLn().split(delim)
    fun readInts() = readStrings().map { it.toInt() }

    val (y,b,r) = readInts()

    println(Math.max(y,Math.max(b-1,r-2)))

}

/**
Alice and Bob are decorating a Christmas Tree.

Alice wants only 3 types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have 𝑦 yellow ornaments, 𝑏 blue ornaments and 𝑟 red ornaments.

In Bob's opinion, a Christmas Tree will be beautiful if:

the number of blue ornaments used is greater by exactly 1 than the number of yellow ornaments, and
the number of red ornaments used is greater by exactly 1 than the number of blue ornaments.
That is, if they have 8 yellow ornaments, 13 blue ornaments and 9 red ornaments, we can choose 4 yellow, 5 blue and 6 red ornaments (5=4+1 and 6=5+1).

Alice wants to choose as many ornaments as possible, but she also wants the Christmas Tree to be beautiful according to Bob's opinion.

In the example two paragraphs above, we would choose 7 yellow, 8 blue and 9 red ornaments. If we do it, we will use 7+8+9=24 ornaments.
That is the maximum number.

Since Alice and Bob are busy with preparing food to the New Year's Eve, they are asking you to find out the maximum number of ornaments
that can be used in their beautiful Christmas Tree!

It is guaranteed that it is possible to choose at least 6 (1+2+3=6) ornaments.

Input
The only line contains three integers 𝑦, 𝑏, 𝑟 (1≤𝑦≤100, 2≤𝑏≤100, 3≤𝑟≤100) — the number of yellow, blue and red ornaments.

It is guaranteed that it is possible to choose at least 6 (1+2+3=6) ornaments.

Output
Print one number — the maximum number of ornaments that can be used.
 */
fun main(args: Array<String>) {
    println(24 == christmasOrnament(mutableListOf(8, 13, 9)))
    println(9 == christmasOrnament(mutableListOf(13, 3, 6)))
    println(30 == christmasOrnament(mutableListOf(10, 12, 20)))
    println(6 == christmasOrnament(mutableListOf(6, 12, 3)))
}

fun christmasOrnament(orns: MutableList<Int>): Int {
    var blue = if (orns[1] > orns[2]) orns[2] - 1 else orns[1]
    return (blue downTo 0).firstOrNull { it in 0..orns[2] && it in 0..orns[0] }?.let { it * 3 } ?: 6
}

fun main() {
    readLine()!!.split(' ').mapIndexed { index, s -> s.toInt() - index }.min()!!.toInt() * 3 + 3
}

fun main() {
    var (y, b, r) = readLine()!!.split(' ').map(String::toInt)
    println("${3 * minOf(y, minOf(b, r))}")
}

fun getOrnamentNumber(b: Int, r: Int): Int {
    if (b != 0) {
        return (b - 1) + b + (b + 1)
    }
    if (r != 0) {
        return (r - 2) + (r - 1) + r
    }

    return 0
}

fun findOrnamentNumber(y: Int, b: Int, r: Int): Int {
    return when (maxOf(y, b, r)) {
        y -> findOrnamentNumber(-1, b, r)
        b -> getOrnamentNumber(0, r)
        r -> getOrnamentNumber(b, 0)
        else -> 0
    }
}

fun main(args: Array<String>) {

    var (strY, strB, strR) = readLine()!!.split(' ')

    val y = strY.toInt()
    val b = strB.toInt()
    val r = strR.toInt()

    print(findOrnamentNumber(y, b, r))

}

import java.util.Scanner;

fun main(){
    val scanner=Scanner(System.`in`)
    val y=scanner.nextInt()
    val b=scanner.nextInt()
    val r=scanner.nextInt()
    val max=Math.max(Math.max(y,b),Math.max(b,y))
    val min=Math.min(Math.min(y,b),Math.min(b,y))
    var result=0
    if(min==r){
        result=r*3-3
    }else if(min==b){
        result=b*3
    }else if(min==y){
        result=y*3
    }
    println("${result}")
}

fun main(args: Array<String>) {

        val input = readLine()!!
        val values = input.split(" ")
        println(Christmas(values[0].toInt(), values[1].toInt(), values[2].toInt()))

}

enum class Color {Blue,Red,Yellow}

fun Christmas(yellowcolor:Int,bluecolor:Int,redcolor:Int):Int
{
    if(yellowcolor==bluecolor && bluecolor==redcolor)
        return (yellowcolor-1)+yellowcolor+(yellowcolor-2)

    return when(if (yellowcolor <= bluecolor && yellowcolor <= redcolor)
        Color.Yellow
    else if (bluecolor <= redcolor && bluecolor <= yellowcolor)
        Color.Blue
    else
        Color.Red){
        Color.Yellow -> if(yellowcolor==bluecolor)
                             yellowcolor+(yellowcolor+1)+(yellowcolor-1)
                        else if (redcolor==bluecolor && (redcolor+bluecolor)-(yellowcolor*2)<3)
                             yellowcolor+(yellowcolor+1)+(yellowcolor-1)
                        else if (bluecolor>redcolor && redcolor-yellowcolor==1)
            yellowcolor+(yellowcolor+1)+(yellowcolor-1)

        else if(redcolor>bluecolor || redcolor==bluecolor ||(bluecolor>redcolor && (redcolor+bluecolor)-(yellowcolor*2)>3))
                            yellowcolor+(yellowcolor+1)+(yellowcolor+2)

                        else
                            yellowcolor+(yellowcolor+1)+(yellowcolor-1)

        Color.Blue-> if(bluecolor==redcolor)
            (bluecolor-2)+bluecolor+(bluecolor-1)
            else
                        (bluecolor+1)+bluecolor+(bluecolor-1)
        else -> redcolor+(redcolor-2)+(redcolor-1)
    }

}

fun main(args: Array<String>) {

    var ligne = readLine()!!.toString()

    val parts = ligne.split(" ")
    val v1 : Int =parts.get(0).toInt()
    val v2 : Int= parts.get(1).toInt()
    val v3 : Int = parts.get(2).toInt()

    var res : String = "";

    if(v1+1 <= v2 && v1+2<=v3){
        res = "$v1 ${v1+1} ${v1+2}"
    }

    if(v2+1 <= v3 && v2-1<=v1){
        res = "${v2-1} ${v2} ${v2+1}"
    }

    if(v3-1 <= v2 && v3-2<=v1){
        res = "${v3-2} ${v3-1} ${v3}"
    }
    println("$res" )
}

fun main() {
    val (y, b, r) = readLine()!!.split(" ").map { it.toInt() }

    val base = listOf(y - 2, b - 1, r).min()!!

    val result = base * 3 - 3

    println(result)
}

fun main() {
    val balls = readLine()!!.split(Regex("\\s+"), 3).map { it.toInt() }
    val min = balls.min()!!

    val max = when (min) {
        1 -> 6
        balls[2] -> 3 * (min - 1)
        else -> 3 * min
    }
    println("$max")
}

fun main() {
    var a = readLine()!!.split(' ')!!.map(String::toInt)
    for (i in 0..2) println(a[i])
    println(minOf(a[0]+1,a[1],a[2]-1)*3)
}

import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)

    var yellow = 1
    var blue = 2
    var red = 3

    yellow = scanner.nextInt()
    blue = scanner.nextInt()
    red = scanner.nextInt()

    val summ = 0

    while ((blue != 1 + yellow || 1 + blue != red) && yellow + 2 != red) {

        if (yellow >= blue)
            yellow = blue - 1
        else if (yellow < blue)
            blue = yellow + 1

        if (blue >= red)
            blue = red - 1
        else if (blue < red)
            red = blue + 1

    }

    print(yellow + blue + red)
}

fun main(){
    fun readLn() = readLine()!!
    fun readStrings(delim: Char = ' ') = readLn().split(delim)
    fun readInts() = readStrings().map { it.toInt() }

    val (y,b,r) = readInts()

    println(3+3*Math.max(y,Math.max(b-1,r-2)))

}

fun getOrnamentNumber(y: Int, b: Int, r: Int): Int {

    if (y != 0) {
        return y + y + (1) + (y + 2)
    }
    if (b != 0) {
        return (b - 1) + b + (b + 1)
    }
    if (r != 0) {
        return (r - 2) + (r - 1) + r
    }

    return 0
}

fun findOrnamentNumber(y: Int, b: Int, r: Int): Int {
    return when (maxOf(y, b, r)) {
        y -> if (b > r) getOrnamentNumber(0, 0, r) else getOrnamentNumber(0, b, 0)

        b -> if (r > y) getOrnamentNumber(y, 0, 0) else getOrnamentNumber(0, 0, r)

        r -> if (y > b) getOrnamentNumber(0, b, 0) else getOrnamentNumber(y, 0, 0)

        else -> 0
    }
}

fun main(args: Array<String>) {
    val (strY, strB, strR) = readLine()!!.split(' ')

    val y = strY.toInt()
    val b = strB.toInt()
    val r = strR.toInt()

    print(findOrnamentNumber(y, b, r))
}

import java.util.Arrays;
import java.util.Scanner;

fun main(){
    B()
}

fun B(){
    val scanner=Scanner(System.`in`)
    val y=scanner.nextInt()
    val b=scanner.nextInt()
    val r=scanner.nextInt()
    val max=Math.max(Math.max(y,b),Math.max(b,y))
    val min=Math.min(Math.min(y,b),Math.min(b,y))
    var result=0
    if(min==y){
        result=y*3
    }else if(min==b){
        result=b*3
    }else if(min==r){
        result=r*3-3
    }
    println("${result}")
}

fun main(args: Array<String>) {
    val (y, b, r) = readLine()!!.split(" ").map(String::toInt)
    if (r - b <= 1) {
        if (r - b <= 1) {
            print(r * 3 - 3)
        } else {
            print(b * 3)
        }
    } else {
        if (b - y <= 1) {
            print(b * 3)
        } else {
            print(y * 3 + 3)
        }
    }
}

fun main() {
    var ybr = readLine()!!.split(' ').map { it.toInt() }

    println(MaxSum(ybr))
}

fun MaxSum(values: List<Int>): Int {
    var middle = values[values.size / 2]
    while (middle - 1 > values.first() && middle + 1 > values.last())
        middle -= 1

    return 3 * middle
}

import java.util.Arrays;
import java.util.Scanner;

fun main(){
    B()
}

fun B(){
    val scanner=Scanner(System.`in`)
    val y=scanner.nextInt()
    val b=scanner.nextInt()
    val r=scanner.nextInt()
    val max=Math.max(Math.max(y,b),Math.max(b,y))
    val min=Math.min(Math.min(y,b),Math.min(b,y))
    var result=0
    if(min==y){
        result=y*3+3
    }else if(min==b){
        result=b*3
    }else if(min==r){
        result=r*3-3
    }
    println("${result}")
}

fun main(args: Array<String>) {
    val array = readLine()!!.split(' ').map(String::toInt)
    var minIndex = array.size - 1
    for (i: Int in array.size - 1 downTo 0) {
        if(array[i]<array[minIndex] - i - minIndex +1){
            minIndex = i
        }
    }
    val minVal = array[minIndex]
    var count = minVal

    for (i: Int in minIndex+1 until array.size) {
        count += minVal + i-minIndex

    }

    for (i: Int in minIndex-1 downTo  0) {
        count += minVal + i-minIndex
    }
}

fun main(args: Array<String>) {
    val ybr = readLine()!!.split(" ")
    val y = ybr[0].toInt()
    val b = ybr[1].toInt()
    val r = ybr[2].toInt()

    // if y is min
    if (y < b && b < r) {
        println(3 * (y + 1))
    } else if (y > b && b > r) {
        println(3 * (r - 1))
    } else {
        println(3 * b)
    }

}

import java.util.*

fun main(args : Array<String>) {
    val reader = Scanner(System.`in`)

    var y:Int
    var b:Int
    var r:Int

    var sum:Int
    y=reader.nextInt()
    b=reader.nextInt()
    r=reader.nextInt()

    r=when {
        b>r -> r
        r>b -> b+1
        else ->r
    }
    b=r-1
    y=b-1

    sum=r+b+y

    println(sum)

}

import java.util.Scanner

fun main(args: Array<String>) {

    val reader = Scanner(System.`in`)
    var a:Int = reader.nextInt()
    var b:Int = reader.nextInt()
    var c:Int = reader.nextInt()
    var ans = a;
    if (ans<b-1) {
        ans = b-1;
    }
    if (ans < c-2) {
        ans = c-2;
    }
    ans = 3 * ans + 3;
    println("$ans")
}

fun main() {
    var (y, b, r) = readLine()!!.split(' ').map(String::toInt)
    println("${3 * minOf(y, minOf(b, r))}")
}

fun main(args: Array<String>) {

        val input = readLine()!!
        val values = input.split(" ")
        println(Christmas(values[0].toInt(), values[1].toInt(), values[2].toInt()))

}

enum class Color {Blue,Red,Yellow}

fun Christmas(yellowcolor:Int,bluecolor:Int,redcolor:Int):Int
{
    if(yellowcolor==bluecolor && bluecolor==redcolor)
        return (yellowcolor-1)+yellowcolor+(yellowcolor-2)

    return when(if (yellowcolor <= bluecolor && yellowcolor <= redcolor)
        Color.Yellow
    else if (bluecolor <= redcolor && bluecolor <= yellowcolor)
        Color.Blue
    else
        Color.Red){
        Color.Yellow -> if(yellowcolor==bluecolor)
                             yellowcolor+(yellowcolor+1)+(yellowcolor-1)
                        else if (redcolor==bluecolor && (redcolor+bluecolor)-(yellowcolor*2)<3)
                             yellowcolor+(yellowcolor+1)+(yellowcolor-1)
                        else if (bluecolor>redcolor && redcolor-yellowcolor==1)
            yellowcolor+(yellowcolor+1)+(yellowcolor-1)

        else if(redcolor>bluecolor || redcolor==bluecolor ||(bluecolor>redcolor && (redcolor+bluecolor)-(yellowcolor*2)>3))
                            yellowcolor+(yellowcolor+1)+(yellowcolor+2)

                        else
                            yellowcolor+(yellowcolor+1)+(yellowcolor-1)

        Color.Blue-> (bluecolor+1)+bluecolor+(bluecolor-1)
        else -> redcolor+(redcolor-2)+(redcolor-1)
    }

}

fun readInts() : List<Int> = readLine()?.split(" ")?.map { it.toInt() }?.toList() ?: emptyList()

fun s1() {
    val (y, b, r) =  readInts()
    when {
        (r in (y..b) && (r-y <= 2)) || (y in r..b) || b in ((r+1) .. (y-1)) -> {
            println(r + (r-1) + (r-2))
        }
        b in (y + 1)..r || r in (y+1)..b-> println(y + (y+1) + (y+2))
        else -> println(b + (b+1) + (b-1))
    }
}

fun main(args: Array<String>) {
    //while (true) { s1() }
    s1()
}

fun main(){
    fun readLn() = readLine()!!
    fun readStrings(delim: Char = ' ') = readLn().split(delim)
    fun readInts() = readStrings().map { it.toInt() }

    val (y,b,r) = readInts()

    println(Math.max(y,Math.max(b-1,r-2)))

}

import kotlin.math.min

fun main(args : Array<String>) {

    val NT = 1//readLine()?.toInt() ?: 0

    for(test in 1..NT){
        val (a, b, c) = readLine()!!.split(" ").map { it.toInt() }
        val d = min(a, min(b - 1, c - 2))
        val ans = 3 * (d + 1)

        println("Case #$test: $ans")

    }

}

fun main(){
    val (a, b,c) = readLine()!!.split(' ')
    var aa=a.toInt()
    var bb=b.toInt()
    var cc=c.toInt()

    var mi = minOf(aa,bb)
    mi=minOf(mi,cc)

    var res=0

    if(mi==aa)
    {
        var needb=aa+1
        var needc=needb+1
        if(needb>bb)
        {
            aa--;
        }
        if(needc>cc)
        {
            aa--;
        }
        res=aa*3+3
    }
    else if(mi==bb)
    {
        var needa=bb-1
        var needc=bb+1

        if(needc>cc)
        {
            needa--;
        }
        res=needa*3+3
    }
    else
    {
        var needb=cc-1
        var needa=needb-1
        res=needa*3+3
    }
    println(res)
}

fun main() {
    val data= readLine()!!.split(" ").map { it.toInt() }
    println(data.min()?.times(3))
}

fun main() {
    val inputs = readLine()!!.split(" ")
    val (yellow, blue, red) = inputs.map { it.toInt() }
    var result = 0

    inputs.forEachIndexed { index, input ->
        val _input = input.toInt()
        when (index) {
            3 -> {
                if (_input - 1 <= blue && _input - 2 <= yellow) {
                    result = _input * 3 - 3
                    return@forEachIndexed
                }
            }
            2 -> {
                if (_input + 1 <= red && _input - 1 <= yellow) {
                    result = _input * 3
                    return@forEachIndexed
                }
            }
            1 -> {
                if (_input + 1 <= blue && _input + 2 <= red) {
                    result = _input * 3 + 3
                    return@forEachIndexed
                }
            }
        }
    }

    print(result)
}

fun main(args: Array<String>) {
    val array = readLine()!!.split(' ').map(String::toInt)
    var minIndex = array.size - 1
    for (i: Int in array.size - 1 downTo 0) {
        if(array[i]<array[minIndex] - i - minIndex +1){
            minIndex = i
        }
    }
    val minVal = array[minIndex]
    var count = minVal

    for (i: Int in minIndex+1 until array.size) {
        count += minVal + i-minIndex

    }

    for (i: Int in minIndex-1 downTo  0) {
        count += minVal + i-minIndex
    }
    println(count)
}

private fun ri() = readLine()!!.toInt()
private fun rli() = readLine()!!.split(" ").map { it.toInt() }

fun main() {
    val (y, b, r) = rli()

    val drb = r - b
    val dry = r - y

    var correction = 0

    if (drb > 1) correction += drb - 1
    if (dry > 2) correction += dry - 1

    print(3 * (r - correction - 1))
}

fun main() {
    var ybr = readLine()!!.split(' ').map { it.toInt() }
    val minIndex = ybr.lastIndexOf(ybr.min())

    when (minIndex) {
        0 -> println(3 * ybr[minIndex] + 3)
        1 -> println(3 * ybr[minIndex])
        2 -> println(3 * ybr[minIndex] - 3)
    }
}

fun main(){
    fun readLn() = readLine()!!
    fun readStrings(delim: Char = ' ') = readLn().split(delim)
    fun readInts() = readStrings().map { it.toInt() }

    val (y,b,r) = readInts()

    println(3+3*Math.max(y,Math.max(b-1,r-2)))

}

private var Y: Int = 0
private var B: Int = 1
private var R: Int = 2
fun main() {
    println(countOrnaments(readLine()?.split(" ")?.map{ it.toInt() }!!))
}

private fun countOrnaments(nums: List<Int>): Int {
    for (r in nums[R] downTo 0) {
        if (nums[B] >= (r - 1) && nums[Y] >= (r - 1))
            return ((3 * r) - 3)
    }
    return -1
}

fun main() {
    val min = readLine()!!.split(Regex("\\s+"), 3).map { it.toInt() }.min()

    println("${min!! * 3}")
}

import java.util.*

fun main(args : Array<String>) {
    val reader = Scanner(System.`in`)

    var y:Int
    var b:Int
    var r:Int

    var sum:Int
    y=reader.nextInt()
    b=reader.nextInt()
    r=reader.nextInt()

    r=if(b>r) r else Math.min(r,b)+1
    b=r-1
    y=b-1

    sum=r+b+y

    println(sum)

}

import java.util.Arrays;
import java.util.Scanner;

fun main(){
    B()
}

fun B(){
    val scanner=Scanner(System.`in`)
    val y=scanner.nextInt()
    val b=scanner.nextInt()
    val r=scanner.nextInt()
    val max=Math.max(Math.max(y,b),Math.max(b,y))
    val min=Math.min(Math.min(y,b),Math.min(b,y))
    var result=0
    if(min==y){
        result=y*3
    }else if(min==r){
        result=r*3-3
    }else if(min==b){
        result=b*3
    }
    println("${result}")
}

import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)

    var yellow = 0
    var blue = 0
    var red = 0

    yellow = scanner.nextInt()
    blue = scanner.nextInt()
    red = scanner.nextInt()

    val summ = 0

    while (blue != 1 + yellow && yellow + 2 != red) {

        if (yellow >= blue)
            yellow = blue - 1
        else if (yellow < blue)
            blue = yellow + 1

        if (blue >= red)
            blue = red - 1
        else if (blue < red)
            red = blue + 1

    }

    print(yellow + blue + red)
}

import kotlin.math.max

fun main() {
    val (a, b, c) = readLine()!!.split(" ").map{ it.toInt() }
    val answer = max(max(a, b - 1), c - 2) * 3 + 3
    println(answer)
}

import java.util.Scanner

fun main(args: Array<String>) {

    val read=Scanner(System.`in`)
    var a=read.nextInt()
    var b=read.nextInt()
    var c=read.nextInt()

    while(true) {

        if((a+1<=b) and (a+2<=c))
        {
            println("${3*b}")
            return
        }
        a--
    }
}

fun main() {
    var arr = readLine()?.split(' ')?.map { e -> Integer.parseInt(e) }

    if(arr != null) {
        var min = Math.min(Math.min(arr[0], arr[1]), arr[2])

        if (min == arr[1])
            min--

        if (min +1 == arr[2])
            min--

        println(min*3 + 3)
    }
}

import java.util.Scanner;

fun main(){
    val scanner=Scanner(System.`in`)
    val y=scanner.nextInt()
    val b=scanner.nextInt()
    val r=scanner.nextInt()
    val max=Math.max(Math.max(y,b),Math.max(b,y))
    val min=Math.min(Math.min(y,b),Math.min(b,y))
    println("${min*3}")
}

fun main(args: Array<String>) {
    val (y, b, r) = readLine()!!.split(" ").map(String::toInt)
    if (r - y >= 1) {
        if (r - b <= 1) {
            print(r * 3 - 3)
        } else {
            print(b * 3)
        }
    } else {
        if (b - y <= 1) {
            print(b * 3)
        } else {
            print(y * 3 + 3)
        }
    }
}

import java.util.*
import java.io.*
import java.math.*

fun main(args : Array<String>) {
    val input = Scanner(System.`in`)
    var y = input.nextInt()
    var b = input.nextInt()
    var r = input.nextInt()
    if (b >= r) {
        b = r - 1
    }
    if (y >= b) {
        y = b - 1
    }
    if (r > b) {
        r = b + 1
    }

    System.err.printf("%d %d %d\n", y, b, r)
    println(y + b + r)
}

import java.util.Arrays;
import java.util.Scanner;

fun main(){
    B()
}

fun B(){
    val scanner=Scanner(System.`in`)
    val y=scanner.nextInt()
    val b=scanner.nextInt()
    val r=scanner.nextInt()
    val max=Math.max(Math.max(y,b),Math.max(b,r))
    val min=Math.min(Math.min(y,b),Math.min(b,r))
    val avg=y+b+r-min-max
    var result=0
    if(min==r){
            result=y*3-3
    }else if(min==b){
            result=b*3
    }else if(min==y){
        if(b<r){
            result=y*3+3
        }else{
            result=y*3
        }
    }
    println("${result}")
}

fun  main( args :  Array<String>)  {

//    val str = "8 13 9"
//    val str ="13 3 6"
//    val str ="3 5 66"
    val str= readLine()!!
    val  ar  =  str.split(" ")
    val y=ar[0].toInt()
    val b=ar[1].toInt()
    val r=ar[2].toInt()

    if (r<=y+2 && r<=b+1) {
        println(r*3-3)
    }

    if (b<=r-1 && b<=y+1) {
        println(b*3)
    }

    if (y<=b-1 && y<=r-2) {
        println(y*3+3)
    }
}

fun main(args: Array<String>) {
    val (y, b, r) = readLine()!!.split(" ").map(String::toInt)
    if (r - b <= 1) {
        if (r - b <= 1) {
            print(r * 3 - 3)
        } else {
            print(b * 3)
        }
    } else {
        if (b - y <= 1) {
            print(b * 3)
        } else {
            print(y * 3 + 3)
        }
    }
}

fun main() {
    val (a, b, c) = readLine()!!.split(" ").map(String::toInt)
    val d = maxOf(a, b - 1, c - 2)
    println(d*3)
}

fun main() {
    var ybr = readLine()!!.split(' ').map { it.toInt() }

    println(MaxSum(ybr))
}

fun MaxSum(values: List<Int>): Int {
    var middle = values[values.size / 2]
    while (middle - 1 > values.first() && middle + 1 > values.last())
        middle -= 1

    return 3 * middle
}

fun main() {
    print( ProblemB(ProblemB.readInput()).solve() )

}

class ProblemB (triple: Triple<Int, Int, Int>) {

    val yellow  = triple.first
    val blue    = triple.second
    val red     = triple.third

    companion object {
        fun readInput() : Triple<Int, Int, Int> {
            val line = readLine()
            var values : List<Int> = line!!.split(" ").map { it.toInt() }
            println (values)
            return Triple(values[0], values[1], values[2])
        }
    }

    fun solve() : Int {
        return solution(blue)
    }

    private fun solution(value: Int): Int {
        return if (yellow >= value - 1 && red >= value + 1) {
            value * 3
        } else
            solution(value - 1)
    }
}

import java.lang.Math.max
import java.lang.Math.min
import java.util.Scanner

fun main()
{
    val reader = Scanner(System.`in`)

    var y = reader.nextInt()
    var b = reader.nextInt()
    var r = reader.nextInt()
    var ans = max(y,b-1)
    ans = max(r-2,ans)
    ans = ans*3 + 3;8
    println(ans)

}

fun main(args: Array<String>) {

        val input = readLine()!!
        val values = input.split(" ")
        println(Christmas(values[0].toInt(), values[1].toInt(), values[2].toInt()))

}

enum class Color {Blue,Red,Yellow}

fun Christmas(yellowcolor:Int,bluecolor:Int,redcolor:Int):Int
{
    if(yellowcolor==bluecolor && bluecolor==redcolor)
        return (yellowcolor-1)+yellowcolor+(yellowcolor-2)

    return when(if (yellowcolor <= bluecolor && yellowcolor <= redcolor)
        Color.Yellow
    else if (bluecolor <= redcolor && bluecolor <= yellowcolor)
        Color.Blue
    else
        Color.Red){
        Color.Yellow -> if(yellowcolor==bluecolor)
            yellowcolor+(yellowcolor+1)+(yellowcolor-1)
            else if(redcolor>bluecolor || redcolor==bluecolor ||(bluecolor>redcolor && (redcolor+bluecolor)-(yellowcolor*2)>3))
                            yellowcolor+(yellowcolor+1)+(yellowcolor+2)

                        else
                            yellowcolor+(yellowcolor+1)+(yellowcolor-1)

        Color.Blue-> (bluecolor+1)+bluecolor+(bluecolor-1)
        else -> redcolor+(redcolor-2)+(redcolor-1)
    }

}

fun main(){
    fun readLn() = readLine()!!
    fun readStrings(delim: Char = ' ') = readLn().split(delim)
    fun readInts() = readStrings().map { it.toInt() }

    val (y,b,r) = readInts()

    println(3+3*Math.max(y,Math.max(b-1,r-2)))

}

fun main(args: Array<String>) {

        val input = readLine()!!
        val values = input.split(" ")
        println(Christmas(values[0].toInt(), values[1].toInt(), values[2].toInt()))

}

enum class Color {Blue,Red,Yellow}

fun Christmas(yellowcolor:Int,bluecolor:Int,redcolor:Int):Int
{
    if(yellowcolor==bluecolor && bluecolor==redcolor)
        return (yellowcolor-1)+yellowcolor+(yellowcolor-2)

    return when(if (yellowcolor <= bluecolor && yellowcolor <= redcolor)
        Color.Yellow
    else if (bluecolor <= redcolor && bluecolor <= yellowcolor)
        Color.Blue
    else
        Color.Red){
        Color.Yellow -> if(redcolor>bluecolor || redcolor==bluecolor )
                            yellowcolor+(yellowcolor+1)+(yellowcolor+2)
                        else if(bluecolor>redcolor && (redcolor+bluecolor)-(yellowcolor*2)>3)
                            yellowcolor+(yellowcolor+1)+(yellowcolor+2)
                        else
                            yellowcolor+(yellowcolor+1)+(yellowcolor-1)

        Color.Blue-> (bluecolor+1)+bluecolor+(bluecolor-1)
        else -> redcolor+(redcolor-2)+(redcolor-1)
    }

}

fun main(args: Array<String>) {
    val ybr = readLine()!!.split(" ")
    val y = ybr[0].toInt()
    val b = ybr[1].toInt()
    val r = ybr[2].toInt()

    // if y is min
    if (y < b && b < r) {
        println(3 * (y + 1))
    }

    // if b is min or equal y
    if (y >= b && b < r) {
        println(3 * b)
    }

    if (y >= b && b >= r) {
        print(3 * (r - 1))
    }
}

fun main () {
    val (y, b, r) = readLine()!!.split(' ').map(String::toInt)
    val v = listOf(y, b, r)
    var x = v.withIndex().minBy { (_, f) -> f }?.index
    x = v[x!!] + ((-x)+1)
    while (x >= b || x >= r) x--
    println(x * 3)
}

import java.util.Scanner
fun main(args: Array<String>) {
val reader = Scanner(System.`in`)
    var y:Int = reader.nextInt()
    var b:Int = reader.nextInt()
    var r:Int = reader.nextInt()
    var ans = r
   var t = r
   if(r-1>b)
    {
    ans=(b+b+1)
    t=b
    }
    else
    {
    ans=ans+(r-1)
    t=r-1
    }
    if(t-1>y)
    {
    ans=(3*y)+1
    }
    else
    {
    ans=ans+(t-1)
    }
    println("$ans\n")
}
/*
fun main(args: Array<String>) {
    var t = readLine()!!.toInt()
    var y = readLine()!!.toInt()
    var b = readLine()!!.toInt()
    var r = readLine()!!.toInt()
    var ans = r
    if(r-1>b)
    {
    ans=(b+b+1)
    t=b
    }
    else
    {
    ans=ans+b
    t=r-1
    }
    if(t-1>y)
    {
    ans=(3*y)+1
    }
    else
    {
    ans=ans+y
    }
    println("$ans\n")
}
*/

import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var (yellow, blue, red) = scan.nextLine().split(" ").map { it.toInt() }
    while (red < blue + 1) {
        blue--
    }
    while (blue < yellow + 1) {
        yellow--
    }
    while (red > blue + 1) {
        red--
    }

    println(yellow + blue + red)
}

fun main() {

    val (a,b,c) = readLine()!!.split(' ').map(String::toInt)
    println(6 + 3*minOf(a, b-1, c-2))
}

fun main() {
    val balls = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    balls[1]--
    balls[2] -= 2
    var min = balls.min()!!
    println(intArrayOf(min, (min + 1), (min + 2)).joinToString(" "))

}


import java.io.*
import java.util.*

fun main() {
    solve(System.`in`, System.out)
}

val MAX_N = (1e6 + 10).toInt()
val INF = (1e9 + 7).toInt()
val MOD = (1e9 + 7).toInt()

fun solve(input: InputStream, output: OutputStream) {
    val reader = InputReader(BufferedInputStream(input))
    val writer = PrintWriter(BufferedOutputStream(output))

    solve(reader, writer)
    writer.close()
}

fun solve(reader: InputReader, writer: PrintWriter) {
    val n = reader.nextInt()
    val m = reader.nextLong()
    val a = reader.nextArrayLong(n).sortedArrayDescending()
    writer.println(search(1, n, n, m, a))
}

fun search(l: Int, r: Int, n: Int, m: Long, a: LongArray): Int {
    if (l > r) {
        return -1
    }
    val x = (l + r) / 2
    if (check(x, n, m, a)) {
        val t = search(l, x - 1, n, m, a)
        return if (t != -1) t else x
    }
    return search(x + 1, r, n, m, a)
}

fun check(x: Int, n: Int, m: Long, a: LongArray): Boolean {
    val a1 = a.filterIndexed { i, v -> v >= i / x }
    val n1 = a1.size
    val k1 = n1 / x
    val r1 = n1 % x
    val count = a1.sum() - x * k1 * (k1 - 1) / 2 - k1 * r1
    return count >= m
}

class InputReader(stream: InputStream) {
    private val reader = BufferedReader(InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer? = null

    operator fun next(): String {
        while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
            try {
                tokenizer = StringTokenizer(reader.readLine())
            } catch (e: IOException) {
                throw RuntimeException(e)
            }

        }
        return tokenizer!!.nextToken()
    }

    fun nextInt(): Int {
        return Integer.parseInt(next())
    }

    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }

    fun nextArrayInt(count: Int): IntArray {
        return nextArrayInt(0, count)
    }

    fun nextArrayInt(start: Int, count: Int): IntArray {
        val a = IntArray(start + count)
        for (i in start until start + count) {
            a[i] = nextInt()
        }
        return a
    }

    fun nextArrayLong(count: Int): LongArray {
        val a = LongArray(count)
        repeat(count) { a[it] = nextLong() }
        return a
    }
}

import java.io.File
import java.util.*

fun main() {
//    val scanner = Scanner(File("input.txt"))
    val scanner = Scanner(System.`in`)

    val numberOfCups = scanner.nextInt()
    val numberOfPages = scanner.nextInt()
    val caffeineInput = Array(numberOfCups) { 0L }
    for (i in 0 until numberOfCups) {
        caffeineInput[i] = scanner.nextLong()
    }
    val caffeine = caffeineInput.sortedDescending().toTypedArray()

    for (targetNumberOfDays in 1..numberOfCups) {
        if (canWriteInNumberOfDays(targetNumberOfDays, numberOfCups, numberOfPages, caffeine)) {
            println(targetNumberOfDays)
            return
        }
    }
    println(-1)
}

fun canWriteInNumberOfDays(
    numberOfDays: Int,
    numberOfCups: Int,
    targetNumberOfPages: Int,
    caffeine: Array<Long> // Sorted by descending
): Boolean {
    val maxNumberOfPages = calculateMaxNumberOfPages(numberOfDays, numberOfCups, caffeine)
    return maxNumberOfPages >= targetNumberOfPages
}

fun calculateMaxNumberOfPages(
    numberOfDays: Int,
    numberOfCups: Int,
    caffeine: Array<Long>
): Long {
    var orderOfCup = 0L
    var numberOfPages = 0L
    for (i in 0 until numberOfCups) {
        numberOfPages += maxOf(caffeine[i] - orderOfCup, 0L)
        if (i % numberOfDays == numberOfDays - 1) ++orderOfCup
    }
    return numberOfPages
}

import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

fun main() {
    val tokenizer = BufferedReader(InputStreamReader(System.`in`)).use { StringTokenizer(it.readText()) }
    val n = tokenizer.nextInt()
    val m = tokenizer.nextInt()
    val a = Array(n) { tokenizer.nextInt() }.apply {
        sort()
        reverse()
    }
    if (a.sum() < m)
        println("-1")
    else {
        var l = 1
        var r = n
        while (l < r) {
            val mid = (l + r) / 2
            if (check(a, m, mid))
                r = mid
            else
                l = mid + 1
        }
        println(l)
    }
}

fun check(a: Array<Int>, m: Int, d: Int): Boolean {
    var sum = 0
    for (i in 0 until a.size) {
        val debuff = i / d
        if (a[i] <= debuff)
            break
        sum += a[i] - debuff
    }
    return sum >= m
}

fun StringTokenizer.nextInt() = nextToken().toInt()
fun StringTokenizer.nextLong() = nextToken().toLong()

import java.io.*
import java.util.*

fun solve() {
    val n = readInt()
    val m = readInt()
    val a = readInts()
    Arrays.sort(a)
    a.reverse()

    fun check(w : Int): Boolean {
        var ww = w
        var count = 0
        var ind = 1
        var nn = 0
        for (i in 0 until w)
            count += a[i]
        while (ww < n) {
            count += if (a[ww] - ind < 0) 0 else a[ww] - ind
            ww++
            nn++
            if (nn == w) {
                nn = 0
                ind++
            }
        }
        return count >= m
    }

    var left = 0
    var right = n
    while (right - left > 1) {
        var mid = (right + left) shr 1
        if (check(mid))
            right = mid
        else
            left = mid
    }

    out.println(if (check(right)) right else -1)
}

fun binmult(a : Long, b : Long, m : Long) : Long {
    if (a == 0L)
        return 0

    if (a % 2 == 1L) {
        val prev = binmult(a - 1, b, m)
        return (prev + b) % m
    } else {
        val half = binmult(a / 2, b, m)
        return (half + half) % m
    }
}

fun binpow(a: Long, n: Long, mod: Long): Long {
    var a = a
    var n = n
    var res: Long = 1
    while (n > 0) {
        if (n and 1 == 1L) {
            res = binmult(res, a, mod)
            res %= mod
            n--
        } else {
            a = binmult(a, a, mod)
            a %= mod
            n = n shr 1
        }
    }
    return res % mod
}

inline fun phi(n: Int): Int {
    var n = n
    var result = n
    var i = 2
    while (i * i <= n) {
        if (n % i == 0) {
            while (n % i == 0)
                n /= i;
            result -= result / i
        }
        ++i
    }
    if (n > 1)
        result -= result / n
    return result
}

var out = PrintWriter(System.out)
var br = BufferedReader(InputStreamReader(System.`in`))
var st = StringTokenizer("")

fun main(args: Array<String>) {
    solve()
    out.close()
}

inline fun readString(): String {
    if (!st.hasMoreTokens())
        st = StringTokenizer(br.readLine())
    return st.nextToken()
}

inline fun readLine() = br.readLine()
inline fun readInt() = readString().toInt()
inline fun readLong() = readString().toLong()
inline fun readDouble() = readString().toDouble()
inline fun readBool() = readString().toBoolean()
inline fun readFloat() = readString().toFloat()

inline fun readInts() = readLine().split(' ').map(String::toInt).toIntArray()

import java.io.*
import java.util.*

fun main() {
    solve(System.`in`, System.out)
}

val MAX_N = (1e6 + 10).toInt()
val INF = (1e9 + 7).toInt()
val MOD = (1e9 + 7).toInt()

fun solve(input: InputStream, output: OutputStream) {
    val reader = InputReader(BufferedInputStream(input))
    val writer = PrintWriter(BufferedOutputStream(output))

    solve(reader, writer)
    writer.close()
}

fun solve(reader: InputReader, writer: PrintWriter) {
    val n = reader.nextInt()
    val m = reader.nextLong()
    val a = reader.nextArrayLong(n).sortedArrayDescending()
    writer.println(search(1, n, n, m, a))
}

fun search(l: Int, r: Int, n: Int, m: Long, a: LongArray): Int {
    if (l > r) {
        return -1
    }
    val x = (l + r) / 2
    if (check(x, n, m, a)) {
        val t = search(l, x - 1, n, m, a)
        return if (t != -1) t else x
    }
    return search(x + 1, r, n, m, a)
}

fun check(x: Int, n: Int, m: Long, a: LongArray): Boolean {
    val a1 = a.filter { it >= n / x }
    val n1 = a1.size
    val k1 = n1 / x
    val r1 = n1 % x
    val count = a1.sum() - x * k1 * (k1 - 1) / 2 - k1 * r1
    return count >= m
}

class InputReader(stream: InputStream) {
    private val reader = BufferedReader(InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer? = null

    operator fun next(): String {
        while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
            try {
                tokenizer = StringTokenizer(reader.readLine())
            } catch (e: IOException) {
                throw RuntimeException(e)
            }

        }
        return tokenizer!!.nextToken()
    }

    fun nextInt(): Int {
        return Integer.parseInt(next())
    }

    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }

    fun nextArrayInt(count: Int): IntArray {
        return nextArrayInt(0, count)
    }

    fun nextArrayInt(start: Int, count: Int): IntArray {
        val a = IntArray(start + count)
        for (i in start until start + count) {
            a[i] = nextInt()
        }
        return a
    }

    fun nextArrayLong(count: Int): LongArray {
        val a = LongArray(count)
        repeat(count) { a[it] = nextLong() }
        return a
    }
}

import java.io.*
import java.util.*

fun solve() {
    val n = readInt()
    val m = readInt()
    val a = readInts()
    Arrays.sort(a)
    a.reverse()

    fun check(w : Int): Boolean {
        var w = w
        var count = 0
        var ind = 0
        for (i in 0 until w)
            count += a[i]
        while (w < n)
            count += if (a[w++] - ++ind < 0) 0 else a[w - 1] - ind

        return count >= m
    }

    var left = 0
    var right = n
    while (right - left > 1) {
        var mid = (right + left) shr 1
        if (check(mid))
            right = mid
        else
            left = mid
    }

    out.println(if (check(right)) right else -1)
}

fun binmult(a : Long, b : Long, m : Long) : Long {
    if (a == 0L)
        return 0

    if (a % 2 == 1L) {
        val prev = binmult(a - 1, b, m)
        return (prev + b) % m
    } else {
        val half = binmult(a / 2, b, m)
        return (half + half) % m
    }
}

fun binpow(a: Long, n: Long, mod: Long): Long {
    var a = a
    var n = n
    var res: Long = 1
    while (n > 0) {
        if (n and 1 == 1L) {
            res = binmult(res, a, mod)
            res %= mod
            n--
        } else {
            a = binmult(a, a, mod)
            a %= mod
            n = n shr 1
        }
    }
    return res % mod
}

inline fun phi(n: Int): Int {
    var n = n
    var result = n
    var i = 2
    while (i * i <= n) {
        if (n % i == 0) {
            while (n % i == 0)
                n /= i;
            result -= result / i
        }
        ++i
    }
    if (n > 1)
        result -= result / n
    return result
}

var out = PrintWriter(System.out)
var br = BufferedReader(InputStreamReader(System.`in`))
var st = StringTokenizer("")

fun main(args: Array<String>) {
    solve()
    out.close()
}

inline fun readString(): String {
    if (!st.hasMoreTokens())
        st = StringTokenizer(br.readLine())
    return st.nextToken()
}

inline fun readLine() = br.readLine()
inline fun readInt() = readString().toInt()
inline fun readLong() = readString().toLong()
inline fun readDouble() = readString().toDouble()
inline fun readBool() = readString().toBoolean()
inline fun readFloat() = readString().toFloat()

inline fun readInts() = readLine().split(' ').map(String::toInt).toIntArray()

import java.io.*
import java.util.*

fun solve() {
    val n = readInt()
    val m = readInt()
    val a = readInts()
    Arrays.sort(a)
    a.reverse()

    fun check(w : Int): Boolean {
        var w = w
        var count = 0
        var ind = 0
        for (i in 0 until w)
            count += a[i]
        while (w < n)
            count += if (a[w++] - ++ind < 0) 0 else a[w - 1] - ind

        return count >= m
    }

    var left = 0
    var right = n - 1
    while (right - left > 1) {
        var mid = (right + left) shr 1
        if (check(mid))
            right = mid
        else
            left = mid
    }

    out.println(if (check(right)) right else -1)
}

fun binmult(a : Long, b : Long, m : Long) : Long {
    if (a == 0L)
        return 0

    if (a % 2 == 1L) {
        val prev = binmult(a - 1, b, m)
        return (prev + b) % m
    } else {
        val half = binmult(a / 2, b, m)
        return (half + half) % m
    }
}

fun binpow(a: Long, n: Long, mod: Long): Long {
    var a = a
    var n = n
    var res: Long = 1
    while (n > 0) {
        if (n and 1 == 1L) {
            res = binmult(res, a, mod)
            res %= mod
            n--
        } else {
            a = binmult(a, a, mod)
            a %= mod
            n = n shr 1
        }
    }
    return res % mod
}

inline fun phi(n: Int): Int {
    var n = n
    var result = n
    var i = 2
    while (i * i <= n) {
        if (n % i == 0) {
            while (n % i == 0)
                n /= i;
            result -= result / i
        }
        ++i
    }
    if (n > 1)
        result -= result / n
    return result
}

var out = PrintWriter(System.out)
var br = BufferedReader(InputStreamReader(System.`in`))
var st = StringTokenizer("")

fun main(args: Array<String>) {
    solve()
    out.close()
}

inline fun readString(): String {
    if (!st.hasMoreTokens())
        st = StringTokenizer(br.readLine())
    return st.nextToken()
}

inline fun readLine() = br.readLine()
inline fun readInt() = readString().toInt()
inline fun readLong() = readString().toLong()
inline fun readDouble() = readString().toDouble()
inline fun readBool() = readString().toBoolean()
inline fun readFloat() = readString().toFloat()

inline fun readInts() = readLine().split(' ').map(String::toInt).toIntArray()