using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        var S = sc.ReadStr();
        var ans = 0;
        var sa = new SuffixArray(S);
        for (int i = 0; i < N; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                var lcp = sa.GetLcp(i, j);
                ans = Math.Max(ans, lcp);
            }
        }
        Console.WriteLine(ans);
    }

    class SuffixArray
    {
        private int N;
        private string S;
        private int[] Rank;
        private int[] Tmp;
        public int[] SA;
        public int[] Lcp;
        private int K;
        private SparseTable<int> ST;
        public SuffixArray(string s)
        {
            S = s;
            N = S.Length;
            CreateSuffixArray();
            CreateLCP();
        }
        private void CreateSuffixArray()
        {
            Rank = new int[N + 1];
            SA = new int[N + 1];
            Tmp = new int[N + 1];
            for (int i = 0; i <= N; i++)
            {
                SA[i] = i;
                Rank[i] = i < N ? S[i] : -1;
            }
            for (K = 1; K <= N; K *= 2)
            {
                Array.Sort(SA, CompareSA);
                Tmp[SA[0]] = 0;
                for (int i = 1; i <= N; i++)
                {
                    Tmp[SA[i]] = Tmp[SA[i - 1]]
                        + (CompareSA(SA[i - 1], SA[i]) < 0 ? 1 : 0);
                }
                for (int i = 0; i <= N; i++)
                {
                    Rank[i] = Tmp[i];
                }
            }
        }
        private int CompareSA(int i, int j)
        {
            if (Rank[i] != Rank[j]) return Rank[i] - Rank[j];
            else
            {
                var ranki = i + K <= N ? Rank[i + K] : -1;
                var rankj = j + K <= N ? Rank[j + K] : -1;
                return ranki - rankj;
            }
        }
        public bool Contains(string t)
        {
            var l = 0;
            var r = N;
            while (r - l > 1)
            {
                var mid = l + (r - l) / 2;
                var index = SA[mid];
                var cmp = string.CompareOrdinal(S, index, t, 0, t.Length);
                if (cmp < 0) l = mid;
                else r = mid;
            }
            return string.CompareOrdinal(S, SA[r], t, 0, t.Length) == 0;
        }
        private void CreateLCP()
        {
            this.Lcp = new int[N + 1];
            for (int i = 0; i <= N; i++) Rank[SA[i]] = i;
            var h = 0;
            Lcp[0] = 0;
            for (int i = 0; i < N; i++)
            {
                var j = SA[Rank[i] - 1];

                if (h > 0) h--;
                for (; j + h < N && i + h < N; h++)
                {
                    if (S[j + h] != S[i + h]) break;
                }
                Lcp[Rank[i] - 1] = h;
            }
            ST = new SparseTable<int>(Lcp);
        }
        public int GetLcp(int a, int b)
        {
            var l = Math.Min(Rank[a], Rank[b]);
            var r = Math.Max(Rank[a], Rank[b]);
            var lcp = ST.GetValue(l, r);
            return Math.Min(lcp, b - a);
        }

        class SparseTable<T> where T : IComparable
        {
            private T[] A;
            private int[,] Table;
            private int[] LogTable;
            private int N;
            private bool IsMin;
            public SparseTable(T[] a, bool min = true)
            {
                A = a;
                IsMin = min;
                N = a.Length;
                CreateTable();
            }
            private void CreateTable()
            {
                LogTable = new int[N + 1];
                for (int i = 2; i < N + 1; i++)
                {
                    LogTable[i] = LogTable[i >> 1] + 1;
                }

                Table = new int[N, LogTable[N] + 1];
                for (int i = 0; i < N; i++)
                {
                    Table[i, 0] = i;
                }

                for (int k = 1; (1 << k) <= N; k++)
                {
                    for (int i = 0; i + (1 << k) <= N; i++)
                    {
                        var index1 = Table[i, k - 1];
                        var index2 = Table[i + (1 << (k - 1)), k - 1];
                        Table[i, k] = Compare(A[index1], A[index2]) < 0 ? index1 : index2;
                    }
                }
            }
            private int Compare(T a, T b)
            {
                return IsMin ? a.CompareTo(b) : b.CompareTo(a);
            }
            public T GetValue(int l, int r)
            {
                var k = LogTable[r - l];
                var value1 = Table[l, k];
                var value2 = Table[r - (1 << k), k];
                return Compare(A[value1], A[value2]) < 0 ? A[value1] : A[value2];
            }
        }
    }


    static Scanner sc = new Scanner();
}
class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public Tuple<int, int> ReadTup(int add = 0)
    {
        return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
    }
    public Tuple<long, long> ReadTupLong(int add = 0)
    {
        return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
    }
    public Tuple<int, int, int> ReadTup3(int add = 0)
    {
        return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add);
    }
    public Tuple<int, int, int, int> ReadTup4(int add = 0)
    {
        return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add);
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
    public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0)
    {
        var array = new Tuple<long, long>[n];
        for (int i = 0; i < n; i++)
        {
            array[i] = this.ReadTupLong(add);
        }
        return array;
    }
    public Tuple<int, int>[] ReadTupArray(int n, int add = 0)
    {
        var array = new Tuple<int, int>[n];
        for (int i = 0; i < n; i++)
        {
            array[i] = this.ReadTup(add);
        }
        return array;
    }
    public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0)
    {
        var array = new Tuple<int, int, int>[n];
        for (int i = 0; i < n; i++)
        {
            array[i] = this.ReadTup3(add);
        }
        return array;
    }
    public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0)
    {
        var array = new Tuple<int, int, int, int>[n];
        for (int i = 0; i < n; i++)
        {
            array[i] = this.ReadTup4(add);
        }
        return array;
    }
}


Measured memory_bytes: 17844