#if true
//#if false
#define UTAKA_DEBUG
#endif

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Text;

namespace UtakaApp
{
    public partial class Program
    {
        public const string ContestName = "abc141";
        public const string ProblemName = "E";

        public static void Main(string[] args)
        {
#if UTAKA_LOCAL
//#if false
            new TestCaseCheckerForAtCoder().TestProblems();
#else
            var console = new MyConsole();
            new Program().Solve(System.Console.In, console);
            console.Flush();
#endif
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        }

        public void Solve(TextReader textReader, IConsole console)
        {
            var cin = new ConsoleInput(textReader);

            int N = cin.ReadInt;
            string S = cin.Read;

            var sa = new SuffixArray(S);
            sa.CalcLcp();

            int ans = 0;

            for (int i = 0; i < N; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    int lcp = sa.GetLcp(i, j);
                    int lcpChecked = Math.Min(lcp, j - i);
                    ans = Math.Max(ans, lcpChecked);
                }
            }

            console.WriteLine(ans.ToString());

//            string sample = "abracadabra";
//
//            var sa = new SuffixArray(sample);
//
//            for (int i = 0; i < sa.SA.Length; i++)
//            {
//                console.WriteLine(sa.SA[i].ToString());
//            }
        }
    }

    public class SparseTableInt
    {
        private int[] heights;
        private int[,] dat;

        public SparseTableInt(int[] vec)
        {
            int n = vec.Length;
            int h = 0;

            while ((1 << h) < n) h++;

            dat = new int[h, 1 << h];

            heights = new int[n + 1];

            for (int i = 2; i <= n; i++)
            {
                heights[i] = heights[i >> 1] + 1;
            }

            for (int i = 0; i < n; i++)
            {
                dat[0, i] = vec[i];
            }

            for (int j = 1; j < h; j++)
            {
                for (int i = 0; i < n; i++)
                {
                    dat[j, i] = Math.Min(dat[j - 1, i], dat[j - 1, Math.Min(i + (1 << (j - 1)), n - 1)]);
                }
            }
        }

        public int Get(int a, int b)
        {
            return Math.Min(dat[heights[b - a], a], dat[heights[b - a], b - (1 << heights[b - a])]);
        }
    }

    public class SparseTable<T>
    {
        private int[] heights;
        private T[,] dat; // i番目から長さ2^kの区間の最小値を記録したテーブル

        public SparseTable(T[] vec)
        {
            int n = vec.Length;
            int h = 0;

            while ((1 << h) < n) h++;

            dat = new T[h, 1 << h];

            heights = new int[n + 1];

            for (int i = 2; i <= n; i++)
            {
                heights[i] = heights[i >> 1] + 1;
            }

            for (int i = 0; i < n; i++)
            {
                dat[0, i] = vec[i];
            }

            for (int k = 1; k < h; k++)
            {
                for (int i = 0; i < n; i++)
                {
                    dat[k, i] = GenericMin(dat[k - 1, i], dat[k - 1, Math.Min(i + (1 << (k - 1)), n - 1)]);
                }
            }
        }

        public T Get(int a, int b)
        {
            // heights[b - a] は、aからbまでの幅に収まる2^n形式の値 すなわち floor(log(b - a))

            return GenericMin(dat[heights[b - a], a], dat[heights[b - a], b - (1 << heights[b - a])]);
        }

        private static T GenericMin(T x, T y)
        {
            return (Comparer<T>.Default.Compare(x, y) < 0) ? x : y;
        }
    }

    public class SuffixArray
    {
        private class SAComparer : IComparer<int>
        {
            private int n;
            private int k;

            private readonly int[] ranks;

            public SAComparer(int n, int k, int[] ranks)
            {
                this.n = n;
                this.k = k;
                this.ranks = ranks;
            }

            public int Compare(int i, int j)
            {
                if (ranks[i] != ranks[j])
                {
                    return ranks[i] - ranks[j];
                }

                int rankIk = (i + k <= n ? ranks[i + k] : -1);
                int rankJk = (j + k <= n ? ranks[j + k] : -1);
                return rankIk - rankJk;
            }
        }

        private string str;

        public int[] SA; // sa[i] : the starting index of the i-th smallest suffix (i = 0, 1, ..., n)

        private int[] lcp; // lcp[i] : the lcp of sa[i] and sa[i + 1] (i = 0, 1, ..., n-1)
        private int[] ranks;
        private int[] tmpRanks;

        public SuffixArray(string inputString)
        {
            str = inputString;

            BuildSuffixArray();
        }

        private void BuildSuffixArray()
        {
            int n = str.Length;

            SA = new int[n + 1];
            ranks = new int[n + 1];
            tmpRanks = new int[n + 1];

            // 最初の1文字は、rankを文字コードにする
            for (int i = 0; i < n; i++)
            {
                SA[i] = i;
                ranks[i] = (int)str[i];
            }

            SA[n] = n;
            ranks[n] = -1; // 空文字列はrank最小

            for (int k = 1; k <= n; k *= 2)
            {
                var saComparer = new SAComparer(n, k, ranks);
                Array.Sort(SA, saComparer);
                tmpRanks[SA[0]] = 0;

                for (int i = 1; i <= n; i++)
                {
                    tmpRanks[SA[i]] = tmpRanks[SA[i - 1]];

                    if (saComparer.Compare(SA[i - 1], SA[i]) < 0)
                    {
                        ++tmpRanks[SA[i]];
                    }
                }

                for (int i = 0; i <= n; i++)
                {
                    ranks[i] = tmpRanks[i];
                }
            }
        }

        private int[] rsa;

//        private SparseTableInt st;
        private SparseTable<int> st;

        public void CalcLcp()
        {
            int n = str.Length;

            rsa = new int[n + 1];
            for (int i = 0; i <= n; i++)
            {
                rsa[SA[i]] = i;
            }

            lcp = new int[n + 1];
            lcp[0] = 0;
            int cur = 0;
            for (int i = 0; i < n; i++)
            {
                int pi = SA[rsa[i] - 1];
                if (cur > 0)
                {
                    cur--;
                }

                for (; pi + cur < n && i + cur < n; ++cur)
                {
                    if (str[pi + cur] != str[i + cur])
                    {
                        break;
                    }
                }

                lcp[rsa[i] - 1] = cur;
            }

//            st = new SparseTableInt(lcp);
            st = new SparseTable<int>(lcp);
        }

        public int GetLcp(int a, int b)
        {
            return st.Get(Math.Min(rsa[a], rsa[b]), Math.Max(rsa[a], rsa[b]));
        }
    }


    public partial class Program
    {
        public const int ModLarge = 1000000007;
    }

    public class ConsoleInput
    {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;

        public ConsoleInput(TextReader stream, char separator = ' ')
        {
            _separator = separator;
            _stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0)
                {
                    return inputStream.Dequeue();
                }

                var tmp = _stream.ReadLine().Split(_separator);
                for (var i = 0; i < tmp.Length; ++i)
                {
                    inputStream.Enqueue(tmp[i]);
                }

                return inputStream.Dequeue();
            }
        }

        public string ReadLine => _stream.ReadLine();
        public int ReadInt => int.Parse(Read);
        public long ReadLong => long.Parse(Read);
        public double ReadDouble => double.Parse(Read);

        public string[] ReadStrArray(long N)
        {
            var ret = new string[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = Read;
            }

            return ret;
        }

        public int[] ReadIntArray(long N)
        {
            var ret = new int[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = ReadInt;
            }

            return ret;
        }

        public long[] ReadLongArray(long N)
        {
            var ret = new long[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = ReadLong;
            }

            return ret;
        }
    }

    public interface IConsole
    {
        void Flush();
        void Write(string str);
        void WriteLine(string str);
    }

    public class MyConsole : IConsole
    {
        public MyConsole()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(sw);
        }

        public void Flush()
        {
            Console.Out.Flush();
        }

        public void Write(string str)
        {
            Console.Write(str);
        }

        public void WriteLine(string str)
        {
            Console.WriteLine(str);
        }
    }

#if UTAKA_LOCAL

    public class DebugConsole : IConsole
    {
        private readonly StringBuilder mSb;

        public DebugConsole()
        {
            mSb = new StringBuilder();
        }

        public void Flush()
        {
            // 何もしない
        }

        public void Write(string str)
        {
            mSb.Append(str);
        }

        public void WriteLine(string str)
        {
            mSb.AppendLine(str);
        }

        public string GetAllOutput()
        {
            return mSb.ToString();
        }
    }

#endif

#if UTAKA_LOCAL

    public class TestCaseCheckerForAtCoder
    {
        private string DirectoryPath => $"../../../../{Program.ContestName}/{Program.ProblemName}";

        private string GetInputFilePath(int testCaseNumber)
        {
            //return $"{DirectoryPath}/sample-{testCaseNumber}.in";
            return $"{DirectoryPath}/in_{testCaseNumber}.txt";
        }

        private string GetOutputFilePath(int testCaseNumber)
        {
            //return $"{DirectoryPath}/sample-{testCaseNumber}.out";
            return $"{DirectoryPath}/out_{testCaseNumber}.txt";
        }

        public bool TestProblem(int testCaseNumber)
        {
            var inputFilePath = GetInputFilePath(testCaseNumber);
            var outputFilePath = GetOutputFilePath(testCaseNumber);

            TextReader inputStream = new StreamReader(inputFilePath);

            var debugConsoleWriter = new DebugConsole();

            new Program().Solve(inputStream, debugConsoleWriter);

            var output = debugConsoleWriter.GetAllOutput();

            TextReader outputStream = new StreamReader(outputFilePath);
            var outputAnswer = outputStream.ReadToEnd();

            Dbg.WriteLine(output);
            Dbg.WriteLine(outputAnswer);

            var isCorrect = output == outputAnswer;

            return isCorrect;
        }

        public void TestProblems()
        {
            var isSuccessAll = true;

            var testCaseNumber = 1;
            while (true)
            {
                var inputFileName = GetInputFilePath(testCaseNumber);
                if (!File.Exists(inputFileName))
                {
                    break;
                }

                Console.WriteLine($"TestCase {testCaseNumber} =====================================================");

                var result = TestProblem(testCaseNumber);

                if (result)
                {
                    Console.WriteLine("Success");
                }
                else
                {
                    isSuccessAll = false;
                    Console.WriteLine("Failure *****");
                }

                testCaseNumber++;
            }

            if (isSuccessAll)
            {
                Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
            }
        }
    }

#endif

#if UTAKA_LOCAL

    public static class Dbg
    {
        public static void WriteLine(string str)
        {
            Console.WriteLine(str);
        }

        public static void Write(string str)
        {
            Console.Write(str);
        }
    }
#else
    public static class Dbg
    {
        public static void WriteLine(string str)
        {
        }

        public static void Write(string str)
        {
        }
    }

#endif
}


Measured memory_bytes: 13792