use std::collections::{HashMap, HashSet};

use proconio::marker::Chars;

fn main() {
    proconio::input! {
        n: i64,
    }
    let mut hs = HashSet::new();
    hs.insert(1);
    for i in 1.. {
        if hs.contains(&n) {
            println!("{i}");
            return;
        }
        let mut new_hs = HashSet::new();
        hs.iter().for_each(|v| {
            let m = v.count_ones() as i64;
            if v - m >= 1 {
                new_hs.insert(v - m);
            }
            if v + m <= n {
                new_hs.insert(v + m);
            }
        });
        if hs == new_hs {
            break;
        }
        hs = new_hs;
    }
    println!("-1");
}

#[cfg(test)]
mod test {
    use super::*;
    #[test]
    fn test() {}
}