fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let a: Vec<usize> = sc.vec(n);

    let mut ng = 0;
    let mut ok = 1 << 50;
    while ok - ng > 1 {
        let b = (ok + ng) / 2;
        if is_ok(&a, b) {
            ok = b;
        } else {
            ng = b;
        }
    }

    println!("{}", ok);
}

fn is_ok(a: &Vec<usize>, upper_bound: usize) -> bool {
    let mut state = State {
        content: vec![],
        upper_bound: upper_bound,
        length: 0,
    };

    let mut prev = 0;
    for &a in a.iter() {
        state.resize(a);
        if prev >= a {
            if !state.increment() {
                return false;
            }
        }

        prev = a;
    }
    true
}

struct State {
    content: Vec<(usize, usize)>,
    length: usize,
    upper_bound: usize,
}

impl State {
    fn increment(&mut self) -> bool {
        let mut tail_zero = 0;
        while let Some((tail_c, length)) = self.content.pop() {
            if tail_c + 1 == self.upper_bound {
                tail_zero += length;
            } else {
                if length > 1 {
                    self.content.push((tail_c, length - 1));
                }
                self.content.push((tail_c + 1, 1));
                if tail_zero > 0 {
                    self.content.push((0, tail_zero));
                }
                return true;
            }
        }
        false
    }
    fn resize(&mut self, new_size: usize) {
        if self.length < new_size {
            let add_length = new_size - self.length;
            self.content.push((0, add_length));
            self.length += add_length;
        } else {
            while let Some((tail_c, length)) = self.content.pop() {
                self.length -= length;
                if self.length < new_size {
                    let add_length = new_size - self.length;
                    self.content.push((tail_c, add_length));
                    self.length += add_length;
                    break;
                }
            }
        }

        assert_eq!(self.length, new_size);
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 11372