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 = sc.vec(n);

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

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

fn solve(a: &Vec<usize>, max: usize) -> bool {
    let mut state = State {
        v: Vec::new(),
        length: 0,
    };

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

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

impl State {
    fn resize(&mut self, new_size: usize) {
        if self.length > new_size {
            while let Some((num, count)) = self.v.pop() {
                self.length -= count;
                if self.length < new_size {
                    let new_count = new_size - self.length;
                    if new_count > 0 {
                        self.v.push((num, new_count));
                    }
                    self.length += new_count;
                    break;
                }
            }
        } else if self.length < new_size {
            let add = new_size - self.length;
            self.v.push((0, add));
            self.length += add;
        }
        assert_eq!(self.length, new_size);
    }

    fn increment(&mut self, max: usize) -> bool {
        let mut suffix = 0;
        while let Some((num, count)) = self.v.pop() {
            if num + 1 == max {
                suffix += count;
            } else {
                if count > 1 {
                    self.v.push((num, count - 1));
                }
                self.v.push((num + 1, 1));
                if suffix > 0 {
                    self.v.push((0, suffix));
                }
                return true;
            }
        }
        return false;
    }
}

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