jiahuimbzuai/CoQuIR huggingface dataset:
//  [c]
#include <stdio.h>

int main(void)
{
  int n = 0, i, flag = 0, min = 1000000000;
  int a[200];

  (void) scanf("%d", &n);
  for (i = 0;i < n; i++)
    (void) scanf("%d", &a[i]);
  for(i = 0;i<n;i++)
  {
    while (a[i] % 2 == 0 && i < min)
    {
      a[i] /= 2;
      i++;
    }
    if (i < min)
      min = i;
  }
  printf("%d\n", min);
  return (0);
}
//  [javascript]
// ABC 081

// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n")
  var n = input[0]; //個数
  var tmp = input[1].split(" ") //数値
  var count = 0;

  var flag = check(tmp)
  while(flag==0) {
    tmp = caculation(tmp)
    count++;
    flag = check(tmp)
  }
  console.log(count)
}

function check(tmp) {
  var flag = 0;
  for(var i=0;i<tmp.length;i++) {
    if(tmp[i]%2 == 1) flag = 1;
  }
  return flag;
}

function caculation(tmp) {
  for(var i=0;i<tmp.length;i++) {
    tmp[i] = tmp[i] / 2;
  }
  return tmp;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main(input) {
    N = parseInt(input.split('\n')[0], 10);
    A = input.split('\n')[1].split(' ');

    L = []
    for (var i = 0; i < N; i++) {
        L.push(parseInt(A[i], 10));
    }
    
    var res = 0
    var flag = false
    while (true) {
        for (var i = 0; i < N; i++) {
            if (L[i]%2 !== 0) {
                flag = true;
            } else {
                L[i] = L[i] / 2
            }
        }
        if (flag) {
            break
        }
        res++
    }

    console.log(res)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
  
    var N = parseInt(input[0], 10);
	//文字列から10進数に変換するときはparseIntを使います
    var a = input[1].split(" ");
  
    var count = 0;
    var x = true;

    while(x == true){
      for(i=0; i<N; i++){
        var A = parseInt(a[i], 10);
         if((A) %2 == 1){
           x = false;
           break;
         }
         a[i] = a[i]/2;
      }
      if(x == true){
        count += 1;
      }
    }
	//出力
    console.log('%d', count);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main(input) {
  var count = input.split("\n");
  var input = count[1].split(" ");
  var map1 = input.map(x => parseInt(x, 10));
  var kazu = 0;
  while(map1.every(y => y%2 == 0)){
  	var map1 = map1.map(z => z/2);
    kazu++;
  }
  console.log(kazu);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main (input) {
  var count = input.split("\n");
  var input = count[1].split(" ");
  var map1 = input.map(x => parseInt(x, 10));
  var kazu = 0;
  while(map1.every(y => y%2 == 0)){
  	var map1 = map1.map(z => z/2);
    kazu++;
  }
  console.log("%d",kazu);
}

console.log(main(require("fs").readFileSync("/dev/stdin","utf8")));
//  [javascript]
function main(input) {
  let inputs = input.split(/\n/);
  let args = inputs[1].split(/\s/);
  let isComplete = false;
  let count = 0;
  let isFirstTime = true;
  while (!isComplete) {
    isComplete = false;
    for (let i = 0;i < inputs[0];i++) {
      if (args[i] % 2 === 0) {
        args[i] = args / 2;
      } else {
        isComplete = true;
      }
    }
    count++;
    if (isFirstTime && isComplete) {
      count = 0;
    }
    isFirstTime = false;
  }
  console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

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

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

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

func main() {
	n := nextInt()
	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	c := 0
	for {
		for i := 0; i < n; i++ {
			if a[i]%2 == 1 {
				fmt.Println(c)
				return
			}
			a[i] /= 2
		}
		c++
	}
}
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

func main() {
	n, err := strconv.Atoi(input())
	if err != nil {
		log.Fatal(err)
	}

	a := make([]int, n)
	for i, _ := range a {
		a[i], err = strconv.Atoi(input())
		if err != nil {
			log.Fatal(err)
		}
	}

	count := 0
	for ; ; count++ {
		for i, v := range a {
			if v % 2 == 1 {
				fmt.Println(count)
				return
			}
			a[i] = v / 2
		}
	}

	fmt.Println(count)
}
//  [go]
package main
 
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
 
func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
 
 
				`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/
 
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())
	//https://atcoder.jp/contests/abc165/tasks/abc165_f
	//https://www.dropbox.com/sh/nx3tnilzqz7df8a/AAA0887IQFx5BcrZcrpRD7uga/ABC165/F?dl=0&subfolder_nav_tracking=1
 
	n := nextInt()
	a := nextInts(n)
 
	ans := -1
	f := true
	for ; f; ans++ {
		for i := 0; i < n; i++ {
			if a[i]%2 != 0 {
				f = false
				break
			}
			a[i] /= 2
		}
	}
 
	//	fmt.Fprintln(out, "[DEBUG]]", a)
	fmt.Fprintln(out, ans)
}
 
//------------------------------------------------------------------------------
 
// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-
 
func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
 
func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}
 
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}
 
func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

/*
1.N個の標準入力を受け付ける
	a.入力がある度、配列に値を格納する
2.3つの数に対して、それぞれ２が何個含まれるか考える
	a.2でn回割れることをそれぞれ確認する
3.その個数を比較して、最小値を求める
*/

func main() {
	var sc = bufio.NewScanner(os.Stdin)
	var split []string
	var values []int
	var n int

	//回数 n を入力
	_, err := fmt.Scanf("%d", &n)
	if err != nil {
		log.Println(err)
	}

	//数字の入力を受け付ける
	var inputNumbers string
	if sc.Scan() {
		inputNumbers = sc.Text()
	}

	split = strings.Split(inputNumbers, " ")
	for _, val := range split {
		intVal, err := strconv.Atoi(val)

		if err != nil {
			log.Println(err)
		}
		values = append(values, intVal)
	}

	//割れる回数を検証する
	divisionCounts := []int{}

	for _, number := range values {
		count := 0
		for true {
			if number%2 == 0 {
				number = number / 2
				count++
			} else {
				divisionCounts = append(divisionCounts, count)
				break
			}
		}
	}

	//divisionCountsの中の最小値を求める
	min := divisionCounts[0]
	for _, count := range divisionCounts {
		if count < min {
			min = count
		}
	}

	answer := strconv.Itoa(min)

	fmt.Println("A:" + answer)
}
//  [go]
package main
import ("fmt")
func main(){
  var(n int 
      y int
      z int
     )
  z = 100
  
  fmt.Scan(&n)
  x := make([]int,n)
  for i:=0;i<n;i++{
    fmt.Scan(&x[i])
  }
  for j:=0;j<n;j++{
    y = 0
    flag:=true
    if flag{
      if x[i]%2==0 {
        x[i] = x[i]/2
        y = y+1
      }else{
        flag = false
      }
      if y < z{
        z = y
      }
    }
    
  } 
  fmt.Println(z)
}
//  [go]
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	
	ans := 0
	for {
		c := 0
		for _, v := range a {
			if v % 2 == 0 {
				c++
			}
		}
		if c == len(a) {
			ans += len(a)
			for i := range a {
				a[i] = a[i] / 2
			}
		} else {
			break
		}
	}
	
	fmt.Println(ans)
}
//  [ruby]
n = gets.to_i
arr = gets.chomp.split(" ").map(&:to_i)

count = 0
while arr.all?{|num| num.even?}
  arr.map!{|num| num/2}
  count += 1
end

puts count
//  [ruby]
H, *A = $stdin.read.split.map(&:to_i)

def div2(x)
  n = 0
  while x % 2 == 0
    x /= 2
    n += 1
  end
  return n
end

puts A.map{|x| div2(x)}.min
//  [ruby]
gets;p gets.split.map{|i|a=i.to_i;(a&-a).to_s(2).size-1}.min
//  [ruby]
n = gets.to_i
nums = gets.split
as = []
n.times do |i|
  as << nums[i].to_i
end

def division(array)
  count_even = 0
  array.each do |num|
    if num.even?
      count_even += 1
    end
  end
  return false if count_even != array.length
  array.map! do |num|
    num / 2
  end
  return true
end

count_divide = 0
while true do |i|
  flag = division(as)
  if flag
    count_divide += 1
  else
    break
  end
end

puts count_divide
//  [ruby]
n = gets.to_i
nums = get.split
as = []
n.times do |i|
  as << nums[i].to_i
end

def division(array)
  count_even = 0
  array.each do |num|
    if num.even?
      count_even += 1
    end
  end
  return false, 0 if count_even != array.length

  array.map do |num|
    num / 2
  end
  return true, array
end

count_divide = 0
30.times do |i|
  flag, as = division(as)
  if flag
    count_divide += 1
  else
    break
  end
end

puts count_divide
//  [ruby]
n = gets.to_i
nums = get.split
as = []
n.times do |i|
  as << nums[i]
end

def division(array)
  count_even = 0
  array.each do |num|
    if num.even?
      count_even += 1
    end
  end
  return false, 0 if count_even != array.length

  array.map do |num|
    num / 2
  end
  return true, array
end

count_divide = 0
30.times do |i|
  flag, as = division(as)
  if flag
    count_divide += 1
  else
    break
  end
end

puts count_divide
//  [rust]
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn counter(n: u32) -> u32 {
    if n % 2 == 0 {
        return 1 + counter(n / 2);
    } else {
        return 0;
    };
}

fn main() {
    let n : u32 = read();
    let avec :Vec<u32> = (0..n).map(|_| read()).collect();
    println!("{}", avec.iter().map(|n| counter(*n)).min().unwrap());
}
//  [rust]
use std::collections::HashMap;
use std::num;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        a: [usize; n],
    }
    let mut e = 0;
    let mut d = 2;
    loop {
        if a.iter().any(|num| num % d != 0) {
            println!("{}", e);
            break;
        } else {
            e += 1;
            d *= 2;
        }
    }
}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut a = a;

    let mut div_count = 0;

    loop {
        let mut divided = true;

        for i in 0..n {
            if a[i] % 2 == 0 {
                a[i] /= 2;
            } else {
                divided = false;
                break;
            }
        }
        if !divided {
            break;
        } else {
            div_count += 1;
        }
    }

    println!("{}", div_count);
}
//  [rust]
use std::io;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).expect("aaaaaaaaaaaaa");

    let mut list: Vec<i32> = line.split_whitespace()
                    .map(|s| s.parse().expect("bbbbbbbbbb"))
                    .collect();

    let mut count: i32 = 0;
    loop {
        let mut temp_list: Vec<i32> = Vec::new();

        for value in list.iter() {
            if value % 2 == 1 {
                println!("{}", count);
                return;
            }

            temp_list.push(value / 2);
        }

        list = temp_list;
        count += 1;
    }
}
//  [rust]
n = ARGF.gets.strip.to_i
a_integers = ARGF.gets.split(/\s+/).collect{|i| i.strip.to_i}

(0..).each do |number_of_operations|
  if a_integers.all?{|i| i.even?}
    a_integers.collect!{|i| i >> 1}
  else
    puts number_of_operations
    break
  end
end
//  [rust]
#![allow(dead_code)]
use crate::scanner::Scanner;
use std::cmp::min;
fn main() {
    let mut scan = Scanner::new();
    let n = scan.read::<usize>();
    let a = scan.readn::<i64>(n);
    let mut ret = 1i64 << 60;
    for i in 0..n {
        let mut b = a[i];
        let mut cnt = 0;
        while b % 2 == 0 {
            b /= 2;
            cnt += 1;
        }
        ret = min(ret, cnt);
    }
    println!("{}", ret);
}
mod scanner {
    use std::io::{stdin, BufReader, Bytes, Read, Stdin};
    use std::str::FromStr;
    pub struct Scanner {
        buf: Bytes<BufReader<Stdin>>,
    }
    impl Scanner {
        pub fn new() -> Scanner {
            Scanner {
                buf: BufReader::new(stdin()).bytes(),
            }
        }
        pub fn read_next<T: FromStr>(&mut self) -> Option<T> {
            let token = self
                .buf
                .by_ref()
                .map(|c| c.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect::<String>();
            token.parse::<T>().ok()
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_next().unwrap()
        }
        pub fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read::<T>()).collect()
        }
        pub fn chars(&mut self) -> Vec<char> {
            self.read::<String>().chars().collect()
        }
    }
}
//  [swift]
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/

//var min, min2, count: Int!
//for i in 1...10 {
//    let x = Int(readLine()!)!
//    if i == 1 {
//        min = x
//        count = 1
//    } else if x < min {
//        min2 = min
//        min = x
//        count = 1
//    } else if x == min && count == 1 {
//        min2 = x
//        count = 2
//    }
//}
//print(min2)

/*************** メインプログラム ***************/

let N = readInt()!
var A = readIntSplit(by: " ")
loop: for i in 0..<30 {
    for j in 0..<N {
        if A[j] % 2 > 0 {
            print(i)
            break loop
        } else {
            A[j] /= 2
        }
    }
}
//  [swift]
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

func main() -> Int {
    var numbers: [Int] = readInts()
    var count = 0
    while true {
        if numbers.filter({ $0 % 2 == 0 }).count == numbers.count {
            numbers = numbers.map { $0 / 2 }
            count += 1
            continue
        } else {
            break
        }
    }
  	return count
}

_ = readInts()
print(main())
//  [swift]

let a = Int(readLine()!)!
var b = readLine()!.split(separator: " ")
    .map({Int($0)!})
var count = 0

while true {
    var c = b.map({$0/2}).filter({$0.isMultiple(of: 2)}).count
    if c != a {
    if count != 0 {
    count += 1
    }
        break
    }
    b = b.map({$0/2})
    count += 1
    
}

print(count)
//  [swift]
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

func main() {
    var numbers: [Int] = readInts()
    var count = 0
    while true {
        if numbers.filter({ $0 % 2 == 0 }).count == numbers.count {
            numbers = numbers.map { $0 / 2 }
            count += 1
            continue
        } else {
            break
        }
    }
}
//  [swift]
for i in A {
  print(i)
}
//  [swift]
a
//  [typescript]
function Main(input) {
  let tmp = input.split("\n");
  let n = parseInt(tmp[0], 10);
  let a = tmp[1].split(" ").map((x) => parseInt(x, 10));

  let ans = 100000;
  for (let i = 0; i < n; i++) {
    let cnt = 0;
    while (a[i] % 2 == 0) {
      cnt++;
      a[i] /= 2;
    }
    ans = Math.min(ans, cnt);
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [typescript]
function Main(input) {
  let tmp = input.split("\n");
  let n = parseInt(tmp[0]);
  let nums = tmp[1].split(" ").map((n) => parseInt(n, 10));
  let ans = 100000;
  for (let i = 0; i < n; i++) {
    let cnt = 0;
    while (nums[i] % 2 === 0) {
      cnt++;
      nums[i] /= 2;
    }
    ans = Math.min(ans, cnt);
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [typescript]
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let n=t.n()
  let a=t.n(n)
  let f=false;
  let ans=0;
  while(!f){
    for(let i=0;i<n;i++){
      if(a[i]%2==0)a[i]/=2
      else {
        f=true
        break
      }
    }
    if(!f)ans++;
  }
  t.o(ans)
}
main()
//  [typescript]
const lines = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

reader.on("line", function (line) {
  lines.push(line);
});
reader.on("close", function () {
  const input = lines[0] as string;
  const numbers = (lines[1] as string).split(" ");

  console.log(countDivide(numbers, Number(input[0]), 0));
});

function countDivide(numbers: string[], inputNum: number, count: number) {
  let nextNumbers: string[] = [];

  numbers.forEach((number) => {
    let halfNumber = Number(number) / 2;
    if (halfNumber % 2 === 0) nextNumbers.push(String(halfNumber));
  });

  if (nextNumbers.length === inputNum) count++;

  if (nextNumbers.length !== inputNum) {
    // if (count !== 0) return count + 1;
    return count;
  }

  count = count + 1;
  console.log(nextNumbers, inputNum, count);
  return countDivide(nextNumbers, inputNum, count);
}
//  [typescript]
const lines = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

reader.on("line", function (line) {
  lines.push(line);
});
reader.on("close", function () {
  const input = lines[0] as string;
  const numbers = (lines[1] as string).split(" ");

  console.log(countDivide(numbers, Number(input[0]), 0));
});

function countDivide(numbers: string[], inputNum: number, count: number) {
  let nextNumbers: string[] = [];

  numbers.forEach((number) => {
    let halfNumber = Number(number) / 2;
    if (halfNumber % 2 === 0) nextNumbers.push(String(halfNumber));
  });

  if (nextNumbers.length !== inputNum) {
    if (count !== 0) return count + 1;
    return count;
  }

  count = count + 1;
  console.log(nextNumbers, inputNum, count);
  return countDivide(nextNumbers, inputNum, count);
}
//  [typescript]
function main(input) {
  	const inputs = input.split("\n")
    const max = inputs[0]
  	const nums = inputs[1].split(" ")
    flag1 = false
    for(let i = 1; i !== max; i++){
 
      input2 = nums.map(item =>{
          if( parseInt(item) / (2**i) % 2  === 0){
              return item
          }else{
              flag1 = true
              return
          }
      })
      if(flag1 === true){
          console.log(i)
          break
      }
  }
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [python]
n=int(input())
import math
for i in reversed(range(math.ceil(n**0.5)+1)):
  if n%i==0:
    print(n//i+i-2)
    break
//  [python]
n = int(input())
m = int(n ** 0.5 + 1)
for i in range(m,0,-1):
    if n % i == 0:
        print((i - 1) + ((n // i) - 1))
        exit()
//  [python]
n = int(input())

nr = int(n**0.5)
for i in range(nr,0,-1):
    if n%i == 0:
        nr2 = n//i
        print(i+nr2-2)
        exit()
//  [python]
n = int(input())

import math
ans = []
for i in range(1,int(math.sqrt(n))):
  if n % i == 0:
    b = int(n/i)
    ans.append(i+b-2)
print(min(ans))
//  [python]
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n = int(input())
    for a in range(1,10**6+1):
        if n%a==0:
            b=n//a
        ans=a+b-2
    print(ans)

if __name__=="__main__":
    main()
//  [python]
N = int(input())

num = set()
for n in range(2, 10**6):
    if N % n == 0:
        num.add(tuple(sorted([n, N//n])))
    if N == n:
        break
ans = (10**12, 10**12)
if not num:
    print(N - 1)
else:
    for s in num:
        if s[0]+s[1] < ans[0]+ans[1]:
            ans = s
    print(ans[0] + ans[1] - 2)
//  [java]
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		long N = sc.nextLong();
		int sqrt = (int)Math.sqrt(N);
		int d = 0;
		for (int i = sqrt; i > 0; i--) {
			if (N % i == 0) {
				d = i;
				break;
			}
		}
		long ans = N / d + d - 2;
		System.out.println(ans);
	}
	
	public static long gcd(long a, long b) {
		long remainder = a % b;
		if (remainder == 0) {
			return b;
		} else {
			return gcd(b, remainder);
		}
	}
}

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());
    }
}
//  [java]
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        long N = sc.nextInt();
        long res;

        long max=1;
        for(int i=1; i<Math.sqrt(N)+1; i++){
            if(N%i==0){

                max = i;

            }
        }
        res = max+N/max-2;
        System.out.println(res);
	}
}
//  [java]
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long n   = Long.parseLong(sc.nextLine());
		long ans = 0;

		for(int i = 1; i < Math.sqrt(n);i++) {

			if(n % i == 0) {

				ans = Math.max(ans, i);
			}

		}

		System.out.println(ans + n / ans - 2);
	}
}
//  [java]
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long tmp1 = 0;
        long tmp2 = 0;
        for (long i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                tmp1 = i;
                if (i != n / i) {
                    tmp2 = n / i;
                }
                if(tmp2 <= tmp1) break;
            }
        }
        long ans = tmp2 + tmp1 -2;
        System.out.println(ans);
    }
}
//  [cpp]
#include <stdio.h>
#include <math.h>

int main()
{
	double N;
	scanf("%lf", &N);

	double i, j;
	for (i = floor(sqrt(N)); i >= 1; i--) {
		j = floor(N / i);
		if (i * j == N)  break;
	}
    printf("%.0lf", -2+i+j);
	return 0;
}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	ll N;
	scanf("%lld", &N);

	int sq = sqrt(N);
	ll saishou = 1e18;
	for (int i = sq; i >= 1; i--) {
		if ((ll)((double)N / i) * i == N) {
			printf("%lld", N / i + i - 2);
			return 0;
		}
	}

	Would you please return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;


int main()
{
    long long int n;
    while(cin>>n)
    {
        long long int x=sqrt((double)n);
        double i;
        double y;
        for(i=x;i>0;i--)
        {
            y=n/i;
            if(y-(long long int)y==0)
            break;
        }
        cout<<(long long int)i+(long long int)y-2<<endl;
    }
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000005 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    ll N;
    cin>>N;
    int n=sqrt(N);
    ll ans=INF;
    for(ll a=1;a<n;a++){
        if(N%a==0){
            ll b=N/a;
            ans=min(ans,a+b-2);
        }
    }
    cout<<ans<<endl;
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define Rep(i, s, n) for (ll i = (ll)s; i < (ll)n; i++)
typedef long long ll;

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    ll n;
    cin >> n;
    ll min = n - 1;
    Rep (i, 2, sqrt(n)) {
        if (n % i == 0) {
            ll j = n / i;
            ll k = (i-1) + (j-1);
            if (min > k) min = k;
        }
    }
    cout << min << endl;
}
//  [cpp]
#include <bits/stdc++.h>          
using namespace std;
typedef long long ll;

vector<ll> prime;//素因数分解で出てきた素数を全て挿入するvector

//O(√n)
//整列済み
/*
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
    for(ll i=2; i<=l; i++){
        if(n%i==0){
        prime_factorize(i);
        prime_factorize(ll(n/i));
        return;
        }
    }
    prime.push_back(n);
    return;
}
*/
int main() {
    ll N;
    cin >> N;
    vector<ll> cnt;
    for (ll i=1; i*i<N; i++) {
        if (N%i==0) {
            cnt.push_back(i+N/i-2);
        }
    }
    sort(cnt.begin(),cnt.end());
    cout << cnt[0] << endl;
    /*
    prime_factorize(N);
    ll n = prime.size();
    vector<ll> vec(n);
    vec[0] = prime[0];
    for (ll i=1; i<n; i++) {
        if (prime[i-1]==prime[i]) {
            vec[i]=vec[i-1]*prime[i];
        }
        else {
            vec[i]=prime[i];
        }
    }
    vector<ll> cnt(n);
    for (ll i=0; i<n; i++) {
        cnt[i] = vec[i] + N/vec[i] - 2;
    }
    sort(cnt.begin(),cnt.end());
    cout << cnt[0] << endl;
    */
}
//  [c]
#include<stdio.h>
#include<math.h>

long solve(long n) {
    long m = 1 + n;
    int cl = ceil(sqrt(n));

    long double tmp;
    for (int i = 1; i <= cl; ++i) {
        tmp = (long double)i + (long double)n/(long double)i;
        if (tmp == (long)tmp && m > tmp) {
            m = tmp;
        }
    }

    return m;
}


int main () {
    long n;
    scanf("%ld", &n);
    long m = solve(n);

    printf("%ld\n", m - 2);
}
//  [c]
#include <stdio.h>

int main() {
	long N,ans;
	scanf("%ld",&N);
	ans = N + 1 - 2;
	for (long i = 1; i*i <= N; i++) {
		long double tmp = (long double)N/(long double)i;
		if (tmp == (long int)tmp) {
			long val = tmp + i - 2;
			if (val < ans) {
				ans = val;
			}
		}
	}
	printf("%ld\n",ans);
	return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t
#include <math.h>

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 20

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

uint64_t get_int(void) {
  uint64_t num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%llu", &num);
#else
#error
#endif
  return num;
}

int main(void) {
    uint64_t num = get_int();
    uint64_t num_2 = sqrt(0.5 + num);
    uint64_t i;
    for(i = num_2; i >= 1; i--) {
        if(num%i) continue;
        printf("%llu\n", i + (num/i) - 2);
        return 0;
    }
    return 0;
}
//  [c]
#include <stdio.h>
#include <math.h>

int main(void)
{
    long n=0,count=0,min=0;
    scanf("%ld",&n);
    for(int i=1;i<sqrt(n);i++){
        if(n%i==0){
            count=(i-1)+(n/i-1);
            if(min>count || min==0) min=count;
        }
    }
    printf("%ld",min);
    return 0;
}
//  [c]
#include<stdio.h>
#define MAXNUM 10000000
int main(void){
  int N,i,j,k;
  int A=MAXNUM;
  int B=MAXNUM;
  scanf("%d",&N);
  for(i=1;i<N/2;i++){
    if(N % i == 0){
      j=i;
      k=N/j;
      if(A+B>=j+k){
        A=j;
        B=k;
      }
    }
  }
  printf("%d",A+B-2);
  return 0;
}
//  [c]
#include<stdio.h>
#define MAXNUM 10000000
int main(void){
  int N,i,j,k;
  int A=MAXNUM;
  int B=MAXNUM;
  scanf("%d",&N);
  for(i=1;i<N;i++){
    if(N % i == 0){
      j=i;
      k=N/j;
      if(A+B>=j+k){
        A=j;
        B=k;
      }
    }
  }
  printf("%d",A+B-2);
  return 0;
}
//  [javascript]
"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 Main = () => {
    let n = nextInt()
    let i = Number.POSITIVE_INFINITY
    let j = Number.POSITIVE_INFINITY
    for(let k = 1; k<=Math.ceil(Math.sqrt(n));k++){
        if(n % k == 0){
            let l = n / k
            if(k+l < i+j){
                [i,j] = [k,l]
            }
        }
    }
    console.log(i+j-2)
}
Main()
//  [javascript]
function factorization(num){
    var dividor=2;
    var workbench=num;
    var ret=[];
    while(workbench>1){
        if(workbench%dividor===0){
            workbench/=dividor;
            ret.push(dividor);
        }else{
            dividor++;
        }
        if(dividor**2>workbench){
            ret.push(workbench);
            break;
        }
    }
    return ret;
}

function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const N=input[0].split(' ')[0]-0;
  var max;
  for(var i=1;i**2<=N;i++){
    if(N%i===0){
      max=i;
    }
  }
  console.log(max+N/max-2);


}




//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
'use strict';
function main(input) {
  const N = parseInt(input);
  let distance = N - 1;
  for (let a = 2; a <= Math.sqrt(N); ++a) {
    let b = N / a;
    if (Number.isInteger(b) && a+b-2 < distance) {
      distance = a+b-2;
    }
  }
  console.log(distance);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function Main(input){
    input = parseInt(input);
    var i = input;
    i = Math.floor(i/2)+1;
    var array = [];
    while(i--){
        if(input%i === 0){
            array.push((input/i)+i);
        }
    }
    console.log(array.reduce((a,b)=>Math.min(a,b))-2);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	var divisor int
	root := int(math.Floor(math.Sqrt(float64(N))))
	//fmt.Println(root)
	for i := 1; i <= root; i++ {
		if N%i == 0 {
			divisor = i
		}
	}
	quotient := N / divisor
	// fmt.Println(quotient, divisor)
	fmt.Println(quotient + divisor - 2)
}
//  [go]
package main

import(
    "fmt"
    "math"
)

func main() {
    var n int
    fmt.Scan(&n)
    if isPrime2(n) {
        fmt.Println(n-1)
        return
    }
    for i:= int(math.Sqrt(float64(n)));i > 0;i-- {
        if n % i == 0 {
            fmt.Println(i+n/i-2)
            return
        }
    }
}

func isPrime2(x int) bool {
    if x == 1 {
        return false
    }
    if x == 2 {
        return true
    }
    if x%2 == 0 {
        return false
    }

    b := true
    rootx := int(math.Sqrt(float64(x)))
    i := 3
    for i <= rootx {
        if x%i == 0 {
            b = false
            break
        }
        i += 2
    }
    return b
}
//  [go]
package main
import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	m := int(math.Ceil(math.Sqrt(float64(n))))
	for j := m; ; j-- {
		if n % j == 0 {
			i := n / j
			d := (i-1) + (j-1)
			fmt.Println(d)
			return
		}
	}
}
//  [go]
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for C - Walk on Multiplication Table
	var N int
	fmt.Scanf("%d", &N)

	var ans int
	var min int = 100000000000
	for i := 1; float64(i) <= math.Sqrt(float64(N)); i++ {
		if N%i != 0 {
			continue
		} else {
			j := N / i
			ans = (i - 1) + (j - 1)

			if min > ans {
				min = ans
			}
		}
	}

	fmt.Println(min)
}
//  [go]
package main

import "fmt"

func main() {
	// Code for C - Walk on Multiplication Table
	var N int
	fmt.Scanf("%d", &N)

	var ans int
	var min int = 10000000
	for i := 1; i <= N; i++ {
		for j := 1; j <= N; j++ {
			if i*j == N {
				ans = (i - 1) + (j - 1)
			}

			if min > ans {
				min = ans
			}
		}
	}

	fmt.Println(min)
}
//  [go]
package main

import "fmt"

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

	min := n
	for i:=1; i<=n; i++{
		for j:=i+1; j<=n; j++{
			if i*j == n && (i-1)+(j-1) < min{
				min = (i-1)+(j-1)
				break
			}
		}
	}

	fmt.Println(min)
}
//  [ruby]
# a * b = N
# ans = a - 1 + b - 1の最小値
n = gets.to_i
a = Math.sqrt(n).to_i
while n % a != 0
  a -= 1
end
b = n / a
puts a + b - 2
//  [ruby]
N = gets.to_i
i = Math.sqrt(N).to_i

while N % i != 0
  i -= 1
end

puts i + N/i -2
//  [ruby]
n = gets.to_i
a = Math.sqrt(n).to_i

while n % a != 0
  a -= 1
end

b = n / a
puts a + b - 2
//  [ruby]
def divisor(num_sqrt)
    (1..num_sqrt).select{ |i| num_sqrt % i == 0 }
end

num = gets.to_i
num_sqrt = Math.sqrt(num).floor
divisions = divisor(num_sqrt)

distance_lists = []

for d in divisions do
  width_count = (d - 1)
  vertical_count = (num / d - 1)
  distance_lists << width_count + vertical_count
end

ans = distance_lists.min 
puts(ans)
//  [ruby]
def divisor(num_sqrt)
    result = []
    i = 1
    while i <= num_sqrt do
      remainder = num_sqrt % i
      if remainder == 0
        result << i
      end 
      i += 1
    end
    return result
end

num = gets.to_i
num_sqrt = Math.sqrt(num).floor
divisions = divisor(num_sqrt)

distance_lists = []

for d in divisions do
  width_count = (d - 1)
  vertical_count = (num / d - 1)
  distance_lists << width_count + vertical_count
end

ans = distance_lists.min 
puts(ans)
//  [rust]
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<i64>();
    let mut sq_n = 0;
    for i in 1..n {
        if i * i > n {
            sq_n = i;
            break;
        }
    }
    if n == 2 {
        println!("1");
        return;
    }
    let primes = get_primes(sq_n as usize);
    let fact_dict = factorize(n, &primes);
    let factors = collect_all_factors(&fact_dict);
    let mut ans_pair = (1, n);
    for num in factors {
        if (ans_pair.0 - 1) + (ans_pair.1 - 1) > (num - 1) + (n / num - 1) {
            ans_pair = (num, n / num);
        }
    }
    println!("{}", (ans_pair.0 - 1) + (ans_pair.1 - 1));
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn get_primes(n: usize) -> Vec<i64> {
    let mut is_prime = vec![true; n + 1];
    let mut primes = Vec::new();
    is_prime[0] = false;
    is_prime[1] = false;

    for i in 2..n + 1 {
        if is_prime[i] {
            primes.push(i as i64);
            let mut j = 2 * i;
            while j < n {
                is_prime[j] = false;
                j += i;
            }
        }
    }
    primes
}

fn factorize(mut num: i64, primes: &Vec<i64>) -> std::collections::HashMap<i64, i64> {
    // max_primes >= (num)^(1/2)
    let mut dict = std::collections::HashMap::new();
    for &p in primes.iter() {
        while num % p == 0 {
            *dict.entry(p).or_insert(0) += 1;
            num /= p;
        }
        if num == 1 {
            break;
        }
    }
    if num != 1 {
        dict.insert(num, 1);
    }
    dict
}

fn pow(n: i64, mut p: i64) -> i64 {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r;
            p /= 2;
        } else {
            ret = ret * r;
            p -= 1;
        }
    }
    ret
}

fn collect_all_factors(dict: &std::collections::HashMap<i64, i64>) -> Vec<i64> {
    let mut ret = vec![1];
    for &key in dict.keys() {
        let mut new = ret.clone();

        for coef in 1..dict[&key] + 1 {
            let coef_1 = pow(key, coef);
            for &num in ret.iter() {
                new.push(num * coef_1);
            }
        }
        ret = new;
    }
    ret
}
//  [rust]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let n = read::<usize>();

    let mut ans = std::usize::MAX;
    
    for a in 1..(n as f64).sqrt().ceil() as usize +1{
        if n % a == 0 {
            ans = std::cmp::min(ans, n/a + a - 2);
        }
    }

    println!("{}", ans);

}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        n: usize,
    }

    let mut ans = n+1;
    let max_range = (n as f64).sqrt().ceil() as usize;
    for i in 1..max_range+1{
        if n % i == 0 {
            let d = n / i;
            ans = std::cmp::min(ans, d+i);
        }
    }

    println!("{}", ans-2);

}
//  [rust]
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let mut ans = std::usize::MAX;

    for i in 1..=((n as f64).sqrt().floor()) as usize {
        for k in 1..=n {
            if i * k == n {
                ans = ans.min(i + k - 2);
            }
        }
    }
    println!("{}", ans);
}
//  [rust]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: u128};

    let half_n = (n as f64).sqrt() as usize;

    let mut dis = std::u128::MAX;

    for i in 1..half_n {
        if n % i as u128 == 0 {
            let x = n / i as u128;
            dis = std::cmp::min(dis, x + i as u128 - 2)
        }
    }

    println!("{}", dis);
}
//  [rust]
use proconio::input;
 
fn main() {
  input! {
    n: usize
  }
  
  let mut a = 1;
  let mut b = n;
  let mut min = usize::max_value();
  while a < b {
    if n % a == 0 {
      min = std::cmp::min(min, (a - 1) + (n / a - 1));
    }
    a += 1;
    b = n / a;
  }
  
  println!("{}", min);
}
//  [swift]
import CoreFoundation
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

let n = arr[0]

var move = 0
var min = n 
for i in 1...Int(sqrt(Double(n))) {
  if( ( n % i ) == 0 ) {
    if( ( n / i ) + i - 2 < min ) {
      min = ( n / i ) + i - 2
    }
  }
}

print( min )