#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

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

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

struct RollingHash {
    hash1: Vec<usize>,
    hash2: Vec<usize>,
    power1: Vec<usize>,
    power2: Vec<usize>,
}

impl RollingHash {
    #[inline]
    fn base1() -> usize {
        1_007
    } 

    #[inline]
    fn base2() -> usize {
        1_009
    } 

    #[inline]
    fn mod1() -> usize {
        1_000_000_007
    } 

    #[inline]
    fn mod2() -> usize {
        1_000_000_009
    } 

    fn new(s: &String) -> Self {
        let n = s.len();
        let s = s.chars().collect::<Vec<_>>();
        let mut hash1 = vec![0; n+1];
        let mut hash2 = vec![0; n+1];
        let mut power1 = vec![1; n+1];
        let mut power2 = vec![1; n+1];
        for i in 0..n {
            hash1[i+1] = (hash1[i]*Self::base1()+(s[i] as usize)) % Self::mod1();
            hash2[i+1] = (hash2[i]*Self::base2()+(s[i] as usize)) % Self::mod2();
            power1[i+1] = power1[i] * Self::base1() % Self::mod1();
            power2[i+1] = power2[i] * Self::base2() % Self::mod2();
        }
        RollingHash {
            hash1: hash1,
            hash2: hash2,
            power1: power1,
            power2: power2,
        }
    }

    fn get(&self, l: usize, r: usize) -> (usize, usize) {
        let mut res1 = self.hash1[r] as isize - (self.hash1[l] * self.power1[r-l] % Self::mod1()) as isize;
        if res1 < 0 {
            res1 += Self::mod1() as isize;
        }
        let mut res2 = self.hash2[r] as isize - (self.hash2[l] * self.power2[r-l] % Self::mod2()) as isize;
        if res2 < 0 {
            res2 += Self::mod2() as isize;
        }
        (res1 as usize, res2 as usize)
    }
}

fn lower_bound<F>(l: usize, r: usize, criterion: F) -> usize
where
F: Fn(usize) -> bool,
{
    let mut l = l;
    let mut r = r;
    while r - l > 1 {
        let mid = l + (r - l) / 2;
        if criterion(mid) {
            r = mid;
        } else {
            l = mid;
        }
    }
    l
}

fn solve() {
    let n = get!(usize);
    let s = get!(String);

    let rh = RollingHash::new(&s);
    
    let check = |d: usize| -> bool {
        let mut map = HashMap::new();
        for i in 0..n-d+1 {
            let hash = rh.get(i, i+d);
            if let Some(&r) = map.get(&hash) {
                if r <= i {
                    return false;
                }
            } else {
                map.insert(hash, i+d);
            }
        }
        true
    };

    println!("{}", lower_bound(0, n/2+1, check));
}


Measured memory_bytes: 8572