using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                var n = ReadIntToken();
                var k = ReadIntToken();
                var table = new bool[n, n];
                for (int i = 0; i < n; i++)
                {
                    var input = Read();
                    for (int j = 0; j < n; j++)
                        table[i, j] = input[j] == '.';
                }
                Cell[,] cells;
                int componentCount;
                BFS(table, out cells, out componentCount);
                var ccWeights = new int[componentCount + 1];
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        if (cells[i, j].CCNumber > 0)
                            ccWeights[cells[i, j].CCNumber]++;
                    }
                }
                var max = int.MinValue;
                for (int z = 0; z < n - k + 1; z++)
                {
                    var activeField = new int[k, k];
                    var ccStats = new int[componentCount + 1];
                    var fieldCCs = new HashSet<int>();
                    var blockedCount = 0;
                    for (int i = z; i < z + k; i++)
                    {
                        for (int j = 0; j < k; j++)
                        {
                            if (cells[i, j].CCNumber > 0)
                            {
                                ccStats[cells[i, j].CCNumber] += 1;
                                fieldCCs.Add(cells[i, j].CCNumber);
                            }
                            else
                                blockedCount++;
                        }
                    }

                    var touchedCCs = GetNeighboursCcs(z, 0, k, n, cells).Concat(fieldCCs).Distinct();
                    max = Math.Max(max, touchedCCs.Select(x => ccWeights[x]).Sum() + blockedCount);

                    for (int w = 1; w < n - k + 1; w++)
                    {
                        for (int i = 0; i < k; i++)
                        {
                            var ccNumber = cells[z + i, w - 1].CCNumber;
                            if (ccNumber == 0)
                                blockedCount--;
                            else
                            {
                                ccStats[ccNumber]--;
                                if (ccStats[ccNumber] == 0)
                                    fieldCCs.Remove(ccNumber);
                            }
                            ccNumber = cells[z + i, w + k - 1].CCNumber;
                            if (ccNumber == 0)
                                blockedCount++;
                            else
                            {
                                if (ccStats[ccNumber] == 0)
                                    fieldCCs.Add(ccNumber);
                               ccStats[ccNumber]++;
                            }
                        }
                        touchedCCs = GetNeighboursCcs(z, w, k, n, cells).Concat(fieldCCs).Distinct();
                        max = Math.Max(touchedCCs.Sum(x => ccWeights[x]) + blockedCount, max);
                    }
                }
                return max;
                //return here
            }
        }

        IEnumerable<int> GetNeighboursCcs(int i, int j, int k, int n, Cell[,] cells)
        {
            return Enumerable.Range(0, k).Select(x => Struct.Create(i - 1, j + x))
                .Concat(Enumerable.Range(0, k).Select(x => Struct.Create(i + k, j + x)))
                .Concat(Enumerable.Range(0, k).Select(x => Struct.Create(i + x, j - 1)))
                .Concat(Enumerable.Range(0, k).Select(x => Struct.Create(i + x, j + k)))
                .Where(x => x.Item1 >= 0 && x.Item1 < n && x.Item2 >= 0 && x.Item2 < n)
                .Select(x => cells[x.Item1, x.Item2].CCNumber).Where(x => x > 0);
        }

        void BFS(bool[,] input, out Cell[,] cells, out int componentCount)
        {
            var n = input.GetLength(0);
            cells = new Cell[n, n];
            var visited = new bool[n, n];
            var componentIndex = 0;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    if (!visited[i, j] && input[i, j])
                        BFS(i, j, cells, input, visited, ++componentIndex);
            componentCount = componentIndex;
        }

        void BFS(int i, int j, Cell[,] cells, bool[,] input, bool[,] visited, int ccIndex)
        {
            var n = input.GetLength(0);
            visited[i, j] = true;
            cells[i, j].CCNumber = ccIndex;
            var neighbours = new[] { Struct.Create(i + 1, j), Struct.Create(i - 1, j), Struct.Create(i, j + 1), Struct.Create(i, j - 1) };
            foreach (var c in neighbours.Where(x => x.Item1 >= 0 && x.Item1 < n && x.Item2 >= 0 && x.Item2 < n && !visited[x.Item1, x.Item2] && input[x.Item1, x.Item2]))
                BFS(c.Item1, c.Item2, cells, input, visited, ccIndex);
        }

        struct Cell
        {
            public int CCNumber { get; set; }
        }

        public static class Struct
        {
            public static Pair<T1, T2> Create<T1,T2>(T1 item1, T2 item2)
            {
                return new Pair<T1, T2> { Item1 = item1, Item2 = item2 };
            }
        }

        public struct Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return int.Parse(Read());
        }

        protected int ReadIntToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return int.Parse(tokens.Dequeue());
        }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLongToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return long.Parse(tokens.Dequeue());
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}


using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace Round356e
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main2(string[] args)
        {
            var result = new List<string>();
            result.Add("500 250");
            bool flag = true;
            for (int i = 0; i < 500; i++)
            {
                if (flag)
                    result.Add(Enumerable.Repeat(".X", 250).JoinStrings(""));
                else
                    result.Add(Enumerable.Repeat("X.", 250).JoinStrings(""));
                flag = !flag;
            }
            File.WriteAllText("c:\\dev\\input", result.JoinStrings("\n"));
        }
        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                var wa = Stopwatch.StartNew();
                FileName = "input";
                var n = ReadIntToken();
                var k = ReadIntToken();
                var table = new bool[n, n];
                for (int i = 0; i < n; i++)
                {
                    var input = Read();
                    for (int j = 0; j < n; j++)
                        table[i, j] = input[j] == '.';
                }
                Cell[,] cells;
                int componentCount;
                BFS(table, out cells, out componentCount);
                var ccWeights = new int[componentCount + 1];
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        if (cells[i, j].CCNumber > 0)
                            ccWeights[cells[i, j].CCNumber]++;
                    }
                }
                Console.WriteLine(wa.Elapsed);
                var max = int.MinValue;
                for (int z = 0; z < n - k + 1; z++)
                {
                    //Console.WriteLine(z + " " + wa.Elapsed);
                    var activeField = new int[k, k];
                    var ccStats = new int[componentCount + 1];
                    var sumOfInternal = 0;
                    var blockedCount = 0;
                    for (int i = z; i < z + k; i++)
                    {
                        for (int j = 0; j < k; j++)
                        {
                            var cc = cells[i, j].CCNumber;
                            if (cc > 0)
                            {
                                if (ccStats[cc] == 0)
                                    sumOfInternal += ccWeights[cc];
                                ccStats[cc] += 1;
                            }
                            else
                                blockedCount++;
                        }
                    }

                    var max2 = Math.Max(max, Sum(GetNeighboursCcs(z, 0, k, n, cells), ccStats, ccWeights) + sumOfInternal + blockedCount);
                    if (max2 > max)
                        max = max2;

                    for (int w = 1; w < n - k + 1; w++)
                    {
                        for (int i = 0; i < k; i++)
                        {
                            var ccNumber = cells[z + i, w - 1].CCNumber;
                            if (ccNumber > 0)
                            {
                                ccStats[ccNumber]--;
                                if (ccStats[ccNumber] == 0)
                                    sumOfInternal -= ccWeights[ccNumber];
                            }
                            else
                                blockedCount--;

                            ccNumber = cells[z + i, w + k - 1].CCNumber;
                            if (ccNumber > 0)
                            {
                                if (ccStats[ccNumber] == 0)
                                    sumOfInternal += ccWeights[ccNumber];
                                ccStats[ccNumber]++;
                            }
                            else
                                blockedCount++;
                        }
                        max2 = Math.Max(max, Sum(GetNeighboursCcs(z, w, k, n, cells), ccStats, ccWeights) + sumOfInternal + blockedCount);
                        if (max2 > max)
                            max = max2;
                    }
                }
                Console.WriteLine(wa.Elapsed);
                return max;
                //return here
            }
        }

        int Sum(IEnumerable<int> list, int[] set, int[] weights)
        {
            var second = new List<int>();
            foreach (var cc in list)
                if (set[cc] == 0)
                    second.Add(cc);
            var sum = 0;
            foreach (var cc in second)
                sum += weights[cc];
            return sum;
        }

        IEnumerable<int> GetNeighboursCcs(int i, int j, int k, int n, Cell[,] cells)
        {
            var result = new HashSet<int>();
            if (i > 0)
                //.Concat(Enumerable.Range(0, k).Select(x => Struct.Create(i + k, j + x)))
                //.Concat(Enumerable.Range(0, k).Select(x => Struct.Create(i + x, j - 1)))
                //.Concat(Enumerable.Range(0, k).Select(x => Struct.Create(i + x, j + k))))
                for (var x = 0; x < k; x++)
                {
                    var cc = cells[i - 1, j + x].CCNumber;
                    if (cc > 0 && !result.Contains(cc))
                        result.Add(cc);
                }
            if (i + k < n)
                for (var x = 0; x < k; x++)
                {
                    var cc = cells[i + k, j + x].CCNumber;
                    if (cc > 0 && !result.Contains(cc))
                        result.Add(cc);
                }
            if (j > 0)
                for (var x = 0; x < k; x++)
                {
                    var cc = cells[i + x, j - 1].CCNumber;
                    if (cc > 0 && !result.Contains(cc))
                        result.Add(cc);
                }
            if (j + k < n)
                for (var x = 0; x < k; x++)
                {
                    var cc = cells[i + x, j + k].CCNumber;
                    if (cc > 0 && !result.Contains(cc))
                        result.Add(cc);
                }
            return result;
        }

        void BFS(bool[,] input, out Cell[,] cells, out int componentCount)
        {
            var n = input.GetLength(0);
            cells = new Cell[n, n];
            var visited = new bool[n, n];
            var componentIndex = 0;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    if (!visited[i, j] && input[i, j])
                        BFS(i, j, cells, input, visited, ++componentIndex);
            componentCount = componentIndex;
        }

        void BFS(int i, int j, Cell[,] cells, bool[,] input, bool[,] visited, int ccIndex)
        {
            var n = input.GetLength(0);
            visited[i, j] = true;
            cells[i, j].CCNumber = ccIndex;
            var neighbours = new[] { Struct.Create(i + 1, j), Struct.Create(i - 1, j), Struct.Create(i, j + 1), Struct.Create(i, j - 1) };
            foreach (var c in neighbours.Where(x => x.Item1 >= 0 && x.Item1 < n && x.Item2 >= 0 && x.Item2 < n && !visited[x.Item1, x.Item2] && input[x.Item1, x.Item2]))
                BFS(c.Item1, c.Item2, cells, input, visited, ccIndex);
        }

        struct Cell
        {
            public int CCNumber { get; set; }
        }

        public static class Struct
        {
            public static Pair<T1, T2> Create<T1,T2>(T1 item1, T2 item2)
            {
                return new Pair<T1, T2> { Item1 = item1, Item2 = item2 };
            }
        }

        public struct Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return int.Parse(Read());
        }

        protected int ReadIntToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return int.Parse(tokens.Dequeue());
        }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLongToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return long.Parse(tokens.Dequeue());
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;
using System.Globalization;
using System.Threading;
using System.Web.Script.Serialization;
using System.Numerics;

class Program
{/*
    public class Point
    {
        public int X;
        public int Y;

        public Point(int x, int y)
        {
            this.X = x;
            this.Y = y;
        }

        public static Point operator +(Point a, Point b)
        {
            return new Point(a.X + b.X, a.Y + b.Y);
        }

        public static Point operator -(Point a, Point b)
        {
            return new Point(a.X - b.X, a.Y - b.Y);
        }

        public double Dist()
        {
            return Math.Sqrt(this.DistRoot());
        }

        public long DistRoot()
        {
            return this.X * (long)this.X + this.Y * (long)this.Y;
        }

        public override string ToString()
        {
            return this.X + " " + this.Y;
        }
    }

    public class Segment
    {
        public Point A;
        public Point B;

        public Segment(Point a, Point b)
        {
            this.A = a;
            this.B = b;
        }

        public double Dist()
        {
            return (this.A - this.B).Dist();
        }

        public long DistRoot()
        {
            return (this.A - this.B).DistRoot();
        }
    }

    private static Point ReadPoint()
    {
        return new Point(ReadInt(), ReadInt());
    }

    public static long ScalarProduct(Point a, Point b)
    {
        return a.X * (long)b.Y - b.X * (long)a.Y;
    }

    public static bool OnLine(Segment line, Point p)
    {
        var v1 = line.B - line.A;
        var v2 = p - line.A;

        if (v2.X == 0 && v2.Y == 0) return true;
        if (v2.X == v1.X && v2.Y == v1.Y) return true;
        if (ScalarProduct(v1, v2) != 0) return false;

        if (v2.DistRoot() > v1.DistRoot()) return false;

        if (v1.X != 0 && v2.X != 0)
        {
            return (v1.X > 0) == (v2.X > 0);
        }

        if (v1.Y != 0 && v2.Y != 0)
        {
            return (v1.Y > 0) == (v2.Y > 0);
        }

        throw new NotSupportedException("wtf?");
    }

    public static bool Crossed(Segment a, Segment b)
    {
        var sp1 = ScalarProduct(a.B - a.A, b.A - a.A);
        var sp2 = ScalarProduct(a.B - a.A, b.B - a.A);
        if (sp1 < 0 && sp2 < 0) return false;
        if (sp1 > 0 && sp2 > 0) return false;

        var sp3 = ScalarProduct(b.B - b.A, a.A - b.A);
        var sp4 = ScalarProduct(b.B - b.A, a.B - b.A);
        if (sp3 < 0 && sp4 < 0) return false;
        if (sp3 > 0 && sp4 > 0) return false;

        return true;
    }

    public static bool CrossedNoTouch(Segment a, Segment b)
    {
        var sp1 = ScalarProduct(a.B - a.A, b.A - a.A);
        var sp2 = ScalarProduct(a.B - a.A, b.B - a.A);
        if (sp1 <= 0 && sp2 <= 0) return false;
        if (sp1 >= 0 && sp2 >= 0) return false;

        var sp3 = ScalarProduct(b.B - b.A, a.A - b.A);
        var sp4 = ScalarProduct(b.B - b.A, a.B - b.A);
        if (sp3 <= 0 && sp4 <= 0) return false;
        if (sp3 >= 0 && sp4 >= 0) return false;

        return true;
    }

    private static double Solve(Point s, Point t, Point a, Point b, Point c)
    {
        var st = new Segment(s, t);
        var ab = new Segment(a, b);
        var bc = new Segment(b, c);
        var ac = new Segment(a, c);

        if (ScalarProduct(b - a, c - a) == 0)
        {
            var q = ab;
            if (q.Dist() < bc.Dist()) q = bc;
            if (q.Dist() < ac.Dist()) q = ac;

            if (Crossed(q, st))
            {
                var d1 = (q.A - s).Dist() + (q.A - t).Dist();
                var d2 = (q.B - s).Dist() + (q.B - t).Dist();
                return Math.Min(d1, d2);
            }

            return (s - t).Dist();
        }

        if (!Crossed(ab, st) && !Crossed(bc, st))
        {
            return (s - t).Dist();
        }

        p[0] = s;
        p[1] = t;
        p[2] = a;
        p[3] = b;
        p[4] = c;

        for (int i = 0; i < d.Length; i++) d[i] = 1e10;

        Go(0, 0);

        return d[1];
    }

    private static Point[] p = new Point[5];
    private static double[] d = new double[5];
    private static void Go(int pos, double dist)
    {
        if (d[pos] < dist) return;
        d[pos] = dist;
        if (pos == 1) return;

    }*/

    private static void Main(string[] args)
    {
        /*
        PushTestData(@"
1
0 0 0 10 -10 20 0 1 10 20
0 0 0 10 -10 20 1 1 10 20
0 0 0 10 -10 20 -1 1 10 20

0 0 0 10 -10 1 0 1 10 1
0 0 0 10 -10 1 1 1 10 1
0 0 0 10 -10 1 -1 1 10 1

");

        int n = ReadInt();
        double[] answer = new double[n];
        for (int i = 0; i < n; i++)
        {
            var s = ReadPoint();
            var t = ReadPoint();
            var a = ReadPoint();
            var b = ReadPoint();
            var c = ReadPoint();

            answer[i] = Solve(s, t, a, b, c);
        }

        Console.WriteLine(string.Join(Environment.NewLine, answer));*/

        PushTestData(@"
3 2
...
XX.
XX.

");

        n = ReadInt();
        k = ReadInt();
        map = new int[n, n];
        sum = new int[n, n];
        sid = new int[n, n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                map[i, j] = ReadCh();

        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                int d = 1 - map[i, j];
                if (i > 0) d += sum[i - 1, j];
                if (j > 0) d += sum[i, j - 1];
                if (i > 0 && j > 0) d -= sum[i - 1, j - 1];
                sum[i, j] = d;
            }

        int nextId = 1;
        segmentSize = new int[n * n + 1];
        markedSegments = new int[n * n + 1];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (map[i, j] + sid[i, j] == 0)
                {
                    MarkSegment(i, j, nextId);
                    nextId++;
                }

        for (int i = 0; i < k; i++)
            for (int j = 0; j < k; j++)
                AddItem(sid[i, j], 1);

        CalculateAnswer(0, 0);

        for (int i = 0; i <= n - k; i++)
        {
            if (i % 2 == 0)
                for (int j = 0; j <= n - k; j++)
                {
                    Change(i, j, 1);
                    CalculateAnswer(i, j);
                    Change(i, j, -1);
                }

            if (i % 2 == 1)
                for (int j = n - k; j >= 0; j--)
                {
                    Change(i, j, 1);
                    CalculateAnswer(i, j);
                    Change(i, j, -1);
                }

            if (i < n - k)
            {
                int j = n - k - (i % 2) * (n - k);
                Change(i, j, 1);
                CalculateAnswer(i, j);
                Change(i, j, -1);
            }
        }

        Console.WriteLine(answer);
    }

    private static void Change(int i, int j, int delta = 1)
    {
        for (int x = 0; x < k; x++)
        {
            AddItem(i + x, j - 1, delta);
            AddItem(i + x, j + k, delta);
            AddItem(i - 1, j + x, delta);
            AddItem(i + k, j + x, delta);
        }
    }

    private static void MoveRight(int i, int j, int delta = 1)
    {
        if (i > 0 && j >= 0) AddItem(sid[i - 1, j], -delta);
        if (i + k < n && j >= 0) AddItem(sid[i + k, j], -delta);
        if (j > 0)
            for (int ii = 0; ii < k; ii++) AddItem(sid[i + ii, j - 1], -delta);

        j += k;
        if (i > 0 && j < n) AddItem(sid[i - 1, j], delta);
        if (i + k < n && j < n) AddItem(sid[i + k, j], delta);
        if (j + 1 < n)
            for (int ii = 0; ii < k; ii++) AddItem(sid[i + ii, j + 1], delta);
    }

    private static void MoveLeft(int i, int j)
    {
        MoveRight(i, j - 1, -1);
    }

    private static void MoveDown(int i, int j)
    {
        if (i > 0)
            for (int jj = 0; jj < k; jj++)
                AddItem(sid[i - 1, j + jj], -1);
        if (j > 0) AddItem(sid[i, j - 1], -1);
        if (j + k < n) AddItem(sid[i, j + k], -1);

        i += k;
        if (i + 1 < n)
            for (int jj = 0; jj < k; jj++)
                AddItem(sid[i + 1, j + jj], 1);

        if (j > 0) AddItem(sid[i, j - 1], 1);
        if (j + k < n) AddItem(sid[i, j + k], 1);

    }

    private static void AddItem(int i, int j, int delta)
    {
        if (i < 0 || j < 0 || i >= n || j >= n) return;
        AddItem(sid[i, j], delta);
    }

    private static void AddItem(int segmentId, int delta)
    {
        if (segmentId <= 0) return;
        int before = markedSegments[segmentId];
        markedSegments[segmentId] += delta;

        if (before == 0) totalSegmentsSize += segmentSize[segmentId];
        if (markedSegments[segmentId] == 0) totalSegmentsSize -= segmentSize[segmentId];
    }

    private static int totalSegmentsSize;
    private static int answer = 0;
    private static int n, k;
    private static int[,] map, sum, sid;
    private static int[] segmentSize, markedSegments;
    private static void MarkSegment(int i, int j, int id)
    {
        if (i < 0 || j < 0 || i >= n || j >= n) return;
        if (map[i, j] == 1) return;
        if (sid[i, j] > 0) return;
        sid[i, j] = id;
        segmentSize[id]++;

        MarkSegment(i - 1, j, id);
        MarkSegment(i + 1, j, id);
        MarkSegment(i, j - 1, id);
        MarkSegment(i, j + 1, id);
    }

    private static int GetCountInside(int i, int j)
    {
        int ans = sum[i + k - 1, j + k - 1];
        if (i > 0) ans -= sum[i - 1, j + k - 1];
        if (j > 0) ans -= sum[i + k - 1, j - 1];
        if (i > 0 && j > 0) ans += sum[i - 1, j - 1];

        return k * k - ans;
    }

    private static void CalculateAnswer(int i, int j)
    {
        int newAnswer = totalSegmentsSize + GetCountInside(i, j);
        answer = Math.Max(answer, newAnswer);
    }

    private static int ReadCh()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans == 'X') return 1;
            if (ans == '.') return 0;
        }
    }

    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n];
        for (int i = 0; i < n; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = ReadInt() - 1;
            int b = ReadInt() - 1;

            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = ReadInt();
            int b = ReadInt();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 16;
    private static StreamReader consoleReader;
    private static MemoryStream testData;

    private static int ReadInt()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong ReadULong()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long ReadLong()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] ReadIntArray(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = ReadInt();
        return ans;
    }

    private static long[] ReadLongArray(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = ReadLong();
        return ans;
    }

    private static char[] ReadString()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            if (pos == n) break;
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s;
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        return ReadDigit() - (int)'0';
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }

    private static string DoubleToString(double x)
    {
        return x.ToString(CultureInfo.InvariantCulture);
    }

    static Program()
    {
        //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);
    }

    private static void PushTestData(string data)
    {
#if !ONLINE_JUDGE
        if (testData == null)
        {
            testData = new MemoryStream();
            consoleReader = new StreamReader(testData);
        }

        var pos = testData.Position;
        var bytes = Encoding.UTF8.GetBytes(data);
        testData.Write(bytes, 0, bytes.Length);
        testData.Flush();
        testData.Position = pos;
#endif
    }
}


using System;
using System.IO;
using System.Linq;
class E { static void Main() { new K(); } }
class K
{
	int F() { return int.Parse(Console.ReadLine()); }
	int[] G() { return Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray(); }
	public K()
	{
		var N = F();
		var loop = Enumerable.Range(0, N);
		var a = new int[N][];
		loop.Select(i =>
		{
			var I = G();
			a[i] = new int[N];
			loop.Select(j =>
			{
				a[i][j] = I[j]; return 0;
			}).ToArray(); return 0;
		}).ToArray();
		loop.Select(k =>
		{
			loop.Select(i =>
			{
				loop.Select(j =>
				{
					a[i][j] = Math.Min(a[i][j], a[i][k] + a[k][j]); return 0;
				}).ToArray();
				return 0;
			}).ToArray();
			return 0;
		}).ToArray();
		Console.WriteLine(a.Select(b => b.Max()).Max());
	}
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    int n;
    int[][] a;
    void Fun(int i, int j, int k)
    {
        try
        {
            throw (i == n ? new ArgumentNullException() : new Exception());
        }
        catch (ArgumentNullException)
        {
            Fun(0, j + 1, k);
            return;
        }
        catch
        {
        }

        try
        {
            throw (j == n ? new ArgumentNullException() : new Exception());
        }
        catch (ArgumentNullException)
        {
            Fun(i, 0, k + 1);
            return;
        }
        catch
        {
        }

        try
        {
            throw (k == n ? new ArgumentNullException() : new Exception());
        }
        catch (ArgumentNullException)
        {
            return;
        }
        catch
        {
        }

        a[i][j] = Math.Min(a[i][j], a[i][k] + a[k][j]);
        Fun(i + 1, j, k);
    }

    void Solve()
    {
        var reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());

        n = int.Parse(reader.ReadLine());
        a = Enumerable.Range(0, n).Select(x => reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray()).ToArray();

        Fun(0, 0, 0);
        Console.WriteLine(a.Max(aa => aa.Max()));
    }

    static void Main()
    {
        new Solver().Solve();
    }

}


using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;

public class E167
{
    public static void Main()
    {
        new E167().Entry();
    }//Main

    void Entry()
    {
        int[] tmp = intSplit(' ');
        int n = tmp[0];
        int m = tmp[1];
        int[] type = new int[n];
        List<int>[] edges = new List<int>[n];
        for (int i = 0; i < n; i++)
            edges[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            tmp = intSplit(' ');
            int a = tmp[0] - 1;
            int b = tmp[1] - 1;
            edges[a].Add(b);
            edges[b].Add(a);
        }//for i
        for (int i = 0; i < n; i++)
        {
            int cnt = 0;
            foreach (int item in edges[i])
            {
                if (type[item]==type[i])
                {
                    cnt++;
                }//if
            }//foreach item
            if (cnt >= 2)
                type[i] = 1;
        }//for i
        StringBuilder sb = new StringBuilder();
        foreach (int item in type)
        {
            sb.Append(item);
        }//foreach item
        Console.WriteLine(sb.ToString());
    }

    string strRead()
    {
        return Console.ReadLine();
    }

    int intRead()
    {
        return int.Parse(Console.ReadLine());
    }

    long longRead()
    {
        return long.Parse(Console.ReadLine());
    }

    double doubleRead()
    {
        return double.Parse(Console.ReadLine());
    }

    string[] strSplit(char a)
    {
        return Console.ReadLine().Split(a);
    }

    int[] intSplit(char a)
    {
        return Array.ConvertAll<string, int>(Console.ReadLine().Split(a), int.Parse);
    }

    long[] longSplit(char a)
    {
        return Array.ConvertAll<string, long>(Console.ReadLine().Split(a), long.Parse);
    }

    double[] doubleSplit(char a)
    {
        return Array.ConvertAll<string, double>(Console.ReadLine().ToString().Split('a'), double.Parse);
    }

}//Template


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgrammingContest.Codeforces.Round82 {
    class C {
        static void Main() {
            var xs = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
            int n = xs[0],
                m = xs[1],
                c0 = xs[2],
                d0 = xs[3];
            List<int[]>zs = new List<int[]>();
            for (int i = 0; i < m; i++) {
                var ys = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
                int d = ys[0] / ys[1];
                zs.Add(new int[] { d * ys[2], d * ys[3] });
            }

            for(int i = 1; i*c0 <= n; i++)
                zs.Add(new int[] { i * c0, i * d0 });

            zs.Sort((a, b) => -(a[1] / a[0] - b[1] / b[0]));
            int res = 0, rest = n;
            for (int i = 0; rest > 0 && i < zs.Count; i++) {
                if (rest >= zs[i][0]) {
                    rest -= zs[i][0];
                    res += zs[i][1];
                }
            }

            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Numerics;

class Program
{
    static TextReader reader;
    static TextWriter writer;
    static Program()
    {
#if ONLINE_JUDGE
        reader = Console.In;
        writer = Console.Out;
#else
        reader = new StreamReader("input.txt");
        writer = new StreamWriter("output.txt");
#endif
    }
    static long gcd(long a, long b)
    {
        if (a < b)
        {
            long t = a;
            a = b;
            b = t;
        }
        return (b > 0) ? gcd(b, a % b) : a;
    }
    static void _235A()
    {
        long n = long.Parse(reader.ReadLine()), ans = n * (n - 1);
        if (n < 3)
            ans = n;
        else if (n % 2 == 1)
            ans *= n - 2;
        else
        {
            long t = (n - 2) / 2;
            for (long i = n - 3; i > (n - 2) / 2; --i)
            {
                long g = gcd(n, i);
                if (g == 1)
                    t = Math.Max(t, i);
            }
            ans *= t;
        }
        writer.Write(Math.Max(ans, (n - 1) * (n - 2) * (n - 3)));
    }
    static void _106C()
    {
        string[] s = reader.ReadLine().Split();
        int n = int.Parse(s[0]), m = int.Parse(s[1]), c0 = int.Parse(s[2]), d0 = int.Parse(s[3]);
        int[] a = new int[m + 1], b = new int[m + 1], c = new int[m + 1], d = new int[m + 1];
        for (int i = 1; i <= m; ++i)
        {
            s = reader.ReadLine().Split();
            a[i] = int.Parse(s[0]);
            b[i] = int.Parse(s[1]);
            c[i] = int.Parse(s[2]);
            d[i] = int.Parse(s[3]);
        }
        int[,] dp = new int[m + 1, n + 1];
        for (int i = 1; i * c0 <= n; ++i)
            dp[0, i * c0] = i * d0;
        for (int i = 1; i <= m; ++i)
        {
            for (int j = 1; j <= n; ++j)
            {
                if (j < c[i])
                    dp[i, j] = dp[i - 1, j];
                else
                {
                    for (int k = 0; k * b[i] <= a[i]; ++k)
                    {
                        int t = c[i] * k;
                        if (t <= j)
                            dp[i, j] = Math.Max(d[i] * k + dp[i - 1, j - t], dp[i, j]);
                    }
                }
            }
        }
        writer.Write(dp[m, n]);
    }
    static long pow(long a, long x, long mod)
    {
        long res = 1;
        while (x > 0)
        {
            if ((x & 1) != 0)
            {
                res = (res * a) % mod;
                --x;
            }
            else
            {
                a = (a * a) % mod;
                x >>= 1;
            }
        }
        return res;
    }
    static void _300C()
    {
        string[] s = reader.ReadLine().Split();
        long a = long.Parse(s[0]), b = long.Parse(s[1]), n = long.Parse(s[2]);
        if (a > b)
        {
            long t = a;
            a = b;
            b = t;
        }
        long[] fact = new long[n + 1];
        fact[0] = fact[1] = 1;
        long mod = 1000000007;
        for (long i = 2; i <= n; ++i)
            fact[i] = fact[i - 1] * i % mod;
        long an = n, bn = 0;
        long ans = 0;
        while (an >= 0)
        {
            long num = an * a + bn * b;
            bool ok = true;
            for (long p = 10; ok && p <= 10000000; p *= 10)
            {
                long t = num % p / (p / 10);
                if (t != a && t != b && (t != 0 || p <= num))
                    ok = false;
            }
            if (ok)
            {
                long c = (((fact[n] * pow(fact[an], mod - 2, mod)) % mod) * pow(fact[bn], mod - 2, mod)) % mod;
                ans += c;
                ans %= mod;
            }
            --an;
            ++bn;
        }
        writer.Write(ans);
    }
    static void Main(string[] args)
    {
        //_235A();
        _106C();
        //_300C();
        reader.Close();
        writer.Close();
    }
}


using System;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			var sr = new InputReader(Console.In);
			//var sr = new InputReader(new StreamReader("input.txt"));
			var task = new Task();
			using (var sw = Console.Out)
				//using (var sw = new StreamWriter("output.txt"))
			{
				task.Solve(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		private int[] a;
		private int[] b;
		private int[] c;
		private int[] d;

		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int32.Parse);
			var n = input[0];
			var m = input[1];
			var cTesto = input[2];
			var dTesto = input[3];
			a = new int[m];
			b = new int[m];
			c = new int[m];
			d = new int[m];
			for (var i = 0; i < m; i++) {
				input = sr.ReadArray(Int32.Parse);
				a[i] = input[0];
				b[i] = input[1];
				c[i] = input[2];
				d[i] = input[3];
			}
			var dp = new int[n + 1, m + 1];
			for (var i = 0; i <= n; i++) {
				for (var j = 1; j <= m; j++) {
					for (var k = 0; k <= a[j - 1] / b[j - 1]; k++) {
						if (i - c[j - 1] * k >= 0) {
							dp[i, j] = Math.Max(dp[i, j], dp[i - c[j - 1] * k, j - 1] + k * d[j - 1]);
						}
					}
				}
			}
			var max = 0;
			for (var i = 0; i <= n; i++) {
				for (var j = 0; j <= m; j++) {
					max = Math.Max(dp[i, j] + ((n - i) / cTesto) * dTesto, max);
				}
			}
			sw.WriteLine(max);
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	public InputReader(TextReader stream)
	{
		sr = stream;
	}

	public void Dispose()
	{
		Dispose(true);
		GC.SuppressFinalize(this);
	}

	public string NextString()
	{
		var result = sr.ReadLine();
		return result;
	}

	public int NextInt32()
	{
		return Int32.Parse(NextString());
	}

	public long NextInt64()
	{
		return Int64.Parse(NextString());
	}

	public string[] NextSplitStrings()
	{
		return NextString()
			.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
	}

	public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
	{
		return NextSplitStrings()
			.Select(s => func(s, CultureInfo.InvariantCulture))
			.ToArray();
	}

	public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
	{
		return
			str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
				.Select(s => func(s, CultureInfo.InvariantCulture))
				.ToArray();
	}

	protected void Dispose(bool dispose)
	{
		if (!isDispose) {
			if (dispose)
				sr.Close();
			isDispose = true;
		}
	}

	~InputReader()
	{
		Dispose(false);
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgrammingContest.Codeforces.Round82 {
    class C {
        static void Main() {
            var xs = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
            int n = xs[0],
                m = xs[1],
                c0 = xs[2],
                d0 = xs[3];

            int[][] ys = new int[m][];
            for (int i = 0; i < ys.Length; i++)
                ys[i] = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);

            int[,] dp = new int[m + 1, n + 1];

            for (int i = 0; i * c0 <= n; i++)
                dp[0, i * c0] = i * d0;

            for (int i = 0; i < m; i++) {
                int d = ys[i][0] / ys[i][1];
                for (int k = 0; k <= n; k++)
                    for (int j = 0; j <= d && k + j * ys[i][2] <= n; j++)
                        dp[i + 1, k + j * ys[i][2]] = Math.Max(dp[i + 1, k + j * ys[i][2]], dp[i, k] + j * ys[i][3]);
            }

            int res = 0;
            for (int i = 0; i <= n; i++)
                res = Math.Max(res, dp[m, i]);

            Console.WriteLine(res);
        }
    }
}


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

namespace codeforces
{
    class Program
    {
        //16:23
        //reading
        static string ReadLine()
        {
            return Console.ReadLine();
        }
        static string[] ReadArray()
        {
            return ReadLine().Split(' ');
        }
        static List<string> ReadList()
        {
            return ReadArray().ToList();
        }
        static List<int> ReadIntList()
        {
            return ReadArray().Select(c => Convert.ToInt32(c)).ToList();
        }
        static List<long> ReadLongList()
        {
            return ReadArray().Select(c => Convert.ToInt64(c)).ToList();
        }
        static List<ulong> ReadULongList()
        {
            return ReadArray().Select(c => Convert.ToUInt64(c)).ToList();
        }
        static int ToInt(string str)
        {
            return Convert.ToInt32(str);
        }
        static long ToInt64(string str)
        {
            return Convert.ToInt64(str);
        }
        static ulong ToUInt64(string str)
        {
            return Convert.ToUInt64(str);
        }

        static void Main(string[] args)
        {
            string str = ReadLine();

            int sum = 0;
            for (int i = 1; i < 7; i++)
            {
                if (str[i] == '0')
                    sum += 9;
                else
                sum += str[i] - '0';
            }
            if (sum + 11 > 21)
                Console.WriteLine(sum + 1);
            else
                Console.WriteLine(sum + 11);
            /*
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;
            Console.WriteLine(elapsedMs);*/
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        string s = ReadToken();
        int ans = 1;
        for (int i = 1; i < 7; i++)
            if (s[i] == '1')
                ans += 10;
            else
                ans += s[i] - '0';
        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
            new Solver().Solve();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


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

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return Next<int>();
        }

        public long NextLong()
        {
            return Next<long>();
        }

        public T Next<T>()
        {
            return (T)Convert.ChangeType(NextString(), typeof(T));
        }

        public IEnumerable<T> NextSeq<T>(int n)
        {
            for (int i = 0; i < n; i++)
                yield return Next<T>();
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print(bool o)
        {
            Print(o ? "YES" : "NO");
        }

        public void PrintLine(bool o)
        {
            PrintLine(o ? "YES" : "NO");
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        public static class P
        {
            public static P<T1, T2> Create<T1, T2>(T1 key, T2 val)
            {
                return new P<T1, T2>(key, val);
            }
        }

        public class P<T1, T2>
        {
            private class PComparer : IComparer<P<T1, T2>>
            {
                private readonly bool? byKey;

                public PComparer(bool? byKey)
                {
                    this.byKey = byKey;
                }

                public int Compare(P<T1, T2> x, P<T1, T2> y)
                {
                    x = x ?? new P<T1, T2>();
                    y = y ?? new P<T1, T2>();

                    if (byKey == true)
                        return Comparer<T1>.Default.Compare(x.Key, y.Key);
                    else if (byKey == false)
                        return Comparer<T2>.Default.Compare(x.Value, y.Value);
                    else
                    {
                        var tr = Comparer<T1>.Default.Compare(x.Key, y.Key);

                        if (tr != 0)
                            tr = Comparer<T2>.Default.Compare(x.Value, y.Value);

                        return tr;
                    }
                }
            }

            public P()
            {
            }

            public P(T1 key, T2 val)
            {
                this.Key = key;
                this.Value = val;
            }

            public T1 Key
            {
                get;
                set;
            }

            public T2 Value
            {
                get;
                set;
            }

            public P<T1, T2> Clone()
            {
                return new P<T1, T2>(Key, Value);
            }

            public static IComparer<P<T1, T2>> KeyComparer
            {
                get { return new PComparer(true); }
            }

            public static IComparer<P<T1, T2>> ValueComparer
            {
                get { return new PComparer(false); }
            }

            public static implicit operator T1(P<T1, T2> obj)
            {
                return obj.Key;
            }

            public static implicit operator T2(P<T1, T2> obj)
            {
                return obj.Value;
            }

            public P<T1, T2> SetKey(T1 key)
            {
                Key = key;
                return this;
            }

            public P<T1, T2> SetValue(T2 value)
            {
                Value = value;
                return this;
            }

            public override string ToString()
            {
                return string.Format("Key: {0}, Value: {1}", Key, Value);
            }

            public override int GetHashCode()
            {
                int hash = 17;
                hash = hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode());
                hash = hash * 31 + ((Equals(Value, default(T1))) ? 0 : Key.GetHashCode());
                return hash;

            }
        }

        #endregion
        public const long MOD = 1000000007;
        public const double EPS = 1e-9;

        private void Solve()
        {
            var n = io.NextInt();
            var k = io.NextInt();
            var h = io.NextInt();

            var m = io.NextSeq<int>(n).ToArray();

            var v = io.NextSeq<int>(n).ToArray();
            var id = Enumerable.Range(0, n).ToArray();

            Array.Sort(id, (a, b) => (m[a] != m[b] ? m[a] - m[b] : v[a] - v[b]));

            var l = 0.0;
            var r = 1/EPS;
            double c = 0;

            var rid = new int[k];

            while(true)
            {
                var cn = (l + r) / 2;

                if (Math.Abs(cn - c) < EPS)
                    break;

                c = cn;

                int j;

                var t = 0;

                for (j = 1; j <= k; j++)
                {
                    while(t < n)
                    {
                        if ((double)j * h + EPS > v[id[t]] * c)
                        {
                            t++;
                        }
                        else
                        {
                            rid[j - 1] = id[t] + 1;
                            break;
                        }
                    }
                    if (t == n)
                        break;

                    t++;
                }

                if (j > k)
                    r = c;
                else
                    l = c;
            }

            for (int i = 0; i < k; i++)
            {
                io.Print((i > 0 ? " " : "") + rid[i]);
            }

        }

        public static void Shuffle<T>(IList<T> list)
        {
            var rnd = new Random(DateTime.Now.Millisecond);

            var n = list.Count;

            while (n > 1)
            {
                n--;
                var k = rnd.Next(n + 1);
                var value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }

    }

}


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

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return Next<int>();
        }

        public long NextLong()
        {
            return Next<long>();
        }

        public T Next<T>()
        {
            return (T)Convert.ChangeType(NextString(), typeof(T));
        }

        public IEnumerable<T> NextSeq<T>(int n)
        {
            for (int i = 0; i < n; i++)
                yield return Next<T>();
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print(bool o)
        {
            Print(o ? "YES" : "NO");
        }

        public void PrintLine(bool o)
        {
            PrintLine(o ? "YES" : "NO");
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        public static class P
        {
            public static P<T1, T2> Create<T1, T2>(T1 key, T2 val)
            {
                return new P<T1, T2>(key, val);
            }
        }

        public class P<T1, T2>
        {
            private class PComparer : IComparer<P<T1, T2>>
            {
                private readonly bool? byKey;

                public PComparer(bool? byKey)
                {
                    this.byKey = byKey;
                }

                public int Compare(P<T1, T2> x, P<T1, T2> y)
                {
                    x = x ?? new P<T1, T2>();
                    y = y ?? new P<T1, T2>();

                    if (byKey == true)
                        return Comparer<T1>.Default.Compare(x.Key, y.Key);
                    else if (byKey == false)
                        return Comparer<T2>.Default.Compare(x.Value, y.Value);
                    else
                    {
                        var tr = Comparer<T1>.Default.Compare(x.Key, y.Key);

                        if (tr != 0)
                            tr = Comparer<T2>.Default.Compare(x.Value, y.Value);

                        return tr;
                    }
                }
            }

            public P()
            {
            }

            public P(T1 key, T2 val)
            {
                this.Key = key;
                this.Value = val;
            }

            public T1 Key
            {
                get;
                set;
            }

            public T2 Value
            {
                get;
                set;
            }

            public P<T1, T2> Clone()
            {
                return new P<T1, T2>(Key, Value);
            }

            public static IComparer<P<T1, T2>> KeyComparer
            {
                get { return new PComparer(true); }
            }

            public static IComparer<P<T1, T2>> ValueComparer
            {
                get { return new PComparer(false); }
            }

            public static implicit operator T1(P<T1, T2> obj)
            {
                return obj.Key;
            }

            public static implicit operator T2(P<T1, T2> obj)
            {
                return obj.Value;
            }

            public P<T1, T2> SetKey(T1 key)
            {
                Key = key;
                return this;
            }

            public P<T1, T2> SetValue(T2 value)
            {
                Value = value;
                return this;
            }

            public override string ToString()
            {
                return string.Format("Key: {0}, Value: {1}", Key, Value);
            }

            public override int GetHashCode()
            {
                int hash = 17;
                hash = hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode());
                hash = hash * 31 + ((Equals(Value, default(T1))) ? 0 : Key.GetHashCode());
                return hash;

            }
        }

        #endregion
        public const long MOD = 1000000007;
        public const double EPS = 1e-17;

        private void Solve()
        {
            var n = io.NextInt();
            var k = io.NextInt();
            var h = io.NextInt();

            var m = io.NextSeq<int>(n).ToArray();

            var v = io.NextSeq<int>(n).ToArray();
            var id = Enumerable.Range(0, n).ToArray();

            Array.Sort(id, (a, b) => (m[a] != m[b] ? m[a] - m[b] : v[b] - v[a]));

            var l = 0.0;
            var r = 1/EPS;
            double c = 0;

            var rid = new int[k];
            var ridx = new int[k];

            while(true)
            {
                var cn = (l + r) / 2;

                if (Math.Abs(cn - c) < EPS)
                    break;

                c = cn;

                int j = 0;

                var t = 0;

                while(t < n)
                {
                    if ((j + 1.0) * h + EPS < v[id[t]] * c)
                    {
                        ridx[j] = id[t] + 1;
                        j++;
                    }

                    t++;

                    if (j == k)
                    {
                        Array.Copy(ridx, rid, ridx.Length);
                        break;
                    }
                }

                if (j == k)
                    r = c;
                else
                    l = c;
            }

            for (int i = 0; i < k; i++)
            {
                io.Print((i > 0 ? " " : "") + rid[i]);
            }

        }

        public static void Shuffle<T>(IList<T> list)
        {
            var rnd = new Random(DateTime.Now.Millisecond);

            var n = list.Count;

            while (n > 1)
            {
                n--;
                var k = rnd.Next(n + 1);
                var value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }

    }

}


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

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return Next<int>();
        }

        public long NextLong()
        {
            return Next<long>();
        }

        public T Next<T>()
        {
            return (T)Convert.ChangeType(NextString(), typeof(T));
        }

        public IEnumerable<T> NextSeq<T>(int n)
        {
            for (int i = 0; i < n; i++)
                yield return Next<T>();
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print(bool o)
        {
            Print(o ? "YES" : "NO");
        }

        public void PrintLine(bool o)
        {
            PrintLine(o ? "YES" : "NO");
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        public static class P
        {
            public static P<T1, T2> Create<T1, T2>(T1 key, T2 val)
            {
                return new P<T1, T2>(key, val);
            }
        }

        public class P<T1, T2>
        {
            private class PComparer : IComparer<P<T1, T2>>
            {
                private readonly bool? byKey;

                public PComparer(bool? byKey)
                {
                    this.byKey = byKey;
                }

                public int Compare(P<T1, T2> x, P<T1, T2> y)
                {
                    x = x ?? new P<T1, T2>();
                    y = y ?? new P<T1, T2>();

                    if (byKey == true)
                        return Comparer<T1>.Default.Compare(x.Key, y.Key);
                    else if (byKey == false)
                        return Comparer<T2>.Default.Compare(x.Value, y.Value);
                    else
                    {
                        var tr = Comparer<T1>.Default.Compare(x.Key, y.Key);

                        if (tr != 0)
                            tr = Comparer<T2>.Default.Compare(x.Value, y.Value);

                        return tr;
                    }
                }
            }

            public P()
            {
            }

            public P(T1 key, T2 val)
            {
                this.Key = key;
                this.Value = val;
            }

            public T1 Key
            {
                get;
                set;
            }

            public T2 Value
            {
                get;
                set;
            }

            public P<T1, T2> Clone()
            {
                return new P<T1, T2>(Key, Value);
            }

            public static IComparer<P<T1, T2>> KeyComparer
            {
                get { return new PComparer(true); }
            }

            public static IComparer<P<T1, T2>> ValueComparer
            {
                get { return new PComparer(false); }
            }

            public static implicit operator T1(P<T1, T2> obj)
            {
                return obj.Key;
            }

            public static implicit operator T2(P<T1, T2> obj)
            {
                return obj.Value;
            }

            public P<T1, T2> SetKey(T1 key)
            {
                Key = key;
                return this;
            }

            public P<T1, T2> SetValue(T2 value)
            {
                Value = value;
                return this;
            }

            public override string ToString()
            {
                return string.Format("Key: {0}, Value: {1}", Key, Value);
            }

            public override int GetHashCode()
            {
                int hash = 17;
                hash = hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode());
                hash = hash * 31 + ((Equals(Value, default(T1))) ? 0 : Key.GetHashCode());
                return hash;

            }
        }

        #endregion
        public const long MOD = 1000000007;
        public const double EPS = 1e-9;

        private void Solve()
        {
            var n = io.NextInt();
            var k = io.NextInt();
            var h = io.NextInt();

            var m = io.NextSeq<int>(n).ToArray();

            var v = io.NextSeq<int>(n).ToArray();
            var id = Enumerable.Range(0, n).ToArray();

            Array.Sort(id, (a, b) => (m[a] != m[b] ? m[a] - m[b] : v[a] - v[b]));

            var l = 0.0;
            var r = 1/EPS;
            double c = 0;
            int t;

            while(true)
            {
                var cn = (l + r) / 2;

                if (Math.Abs(cn - c) < EPS)
                    break;

                c = cn;

                int j;

                t = 0;

                for (j = 1; j <= k; j++)
                {
                    while(t < n && (double)j * h + EPS > v[id[t]] * c)
                    {
                        t++;
                    }
                    if (t == n) break;
                    t++;
                }

                if (j > k)
                    r = c;
                else
                    l = c;
            }

            t = 0;

            for (var j = 1; j <= k; j++)
            {
                while (t < n && (double)j * h + EPS > v[id[t]] * c)
                {
                    if (j > 1)
                        io.Print(" ");

                    t++;

                    io.Print(id[t] + 1);
                }
                t++;
            }

        }

        public static void Shuffle<T>(IList<T> list)
        {
            var rnd = new Random(DateTime.Now.Millisecond);

            var n = list.Count;

            while (n > 1)
            {
                n--;
                var k = rnd.Next(n + 1);
                var value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }

    }

}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace taskC
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,] g = new int[n+1, n+1];
            int number = int.Parse(Console.ReadLine());
            int[] data;
            for (int i = 0; i < number; i++)
            {
                data = Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse);
                g[data[0], data[1]] = 1;
                g[data[1], data[0]] = 1;
            }

            number = int.Parse(Console.ReadLine());
            for (int i = 0; i < number; i++)
            {
                data = Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse);
                g[data[0], data[1]] = -1;
                g[data[1], data[0]] = -1;
            }

            /*for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    Console.Write("{0}\t", g[i, j]);
                }
                Console.WriteLine();
            }*/

            HashSet<int> already = new HashSet<int>();
            List<int> current;
            HashSet<int> currentSet;
            int max = 0;

            for (int i = 1; i <= n; i++)
            {
                if (!already.Contains(i))
                {
                    currentSet = new HashSet<int>();
                    current = new List<int>();

                    currentSet.Add(i);
                    current.Add(i);
                    already.Add(i);
                    int index = 0;
                    bool fall = false;
                    while (index < current.Count)
                    {

                        for (int j = 1; j <= n; j++)
                        {
                            if ((current[index] != j) && (g[current[index], j] == 1) && !currentSet.Contains(j))
                            {
                                current.Add(j);
                                currentSet.Add(j);
                                already.Add(j);
                            }
                            else if ((g[current[index],j]==-1) && currentSet.Contains(j))
                            {
                                fall = true;
                            }
                        }
                        if (fall) break;
                        index++;
                    }
                    if (!fall)
                    {
                        max = Math.Max(max, currentSet.Count);
                    }
                }

            }
            Console.WriteLine(max);
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Party
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static int[] p;
        private static int[] size;

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve(args));
            writer.Flush();
        }

        private static int Solve(string[] args)
        {
            int n = Next();

            p = new int[n];

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

            int k = Next();
            for (int i = 0; i < k; i++)
            {
                int u = Next() - 1;
                int v = Next() - 1;
                int pu = GP(u);
                int pv = GP(v);
                if (pu != pv)
                {
                    p[pu] = pv;
                    size[pv] += size[pu];
                }
            }

            var f = new bool[n];
            int m = Next();
            for (int i = 0; i < m; i++)
            {
                int u = Next() - 1;
                int v = Next() - 1;
                int pu = GP(u);
                int pv = GP(v);
                if (pu == pv)
                {
                    f[pu] = true;
                }
            }

            int max = 0;
            for (int i = 0; i < n; i++)
            {
                if (p[i] == i && !f[i] && size[i] > max)
                    max = size[i];
            }

            return max;
        }

        private static int GP(int i)
        {
            if (i == p[i])
                return i;
            return p[i] = GP(p[i]);
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.IO;

class Program
{

    void solve()
    {

        int n = nextInt();
        List<int>[] likes = new List<int>[n];
        List<int>[] disLikes = new List<int>[n];

        for (int i = 0; i < n; i++)
        {
            likes[i] = new List<int>();
            disLikes[i] = new List<int>();

        }
        int k = nextInt();
        for (int i = 0; i < k; i++)
        {
            int a = nextInt() - 1;
            int b = nextInt() - 1;
            likes[a].Add(b);
            likes[b].Add(a);
        }
        int m = nextInt();
        for (int i = 0; i < m; i++)
        {
            int a = nextInt() - 1;
            int b = nextInt() - 1;
            disLikes[a].Add(b);
            disLikes[b].Add(a);
        }
        bool[] vis = new bool[n];
        bool[] curVis = new bool[n];
        int res = 0;
        for (int i = 0; i < n; i++)
            if (!vis[i])
            {

                List<int> lVis = new List<int>();
                dfs(i, vis, likes, disLikes,lVis,curVis,n);
                int num = lVis.Count;
                if (num <= res)
                    continue;
                foreach (int x in lVis)
                    curVis[x] = true;
                bool ok = true;
                foreach (int x in lVis)
                {
                    foreach (int y in disLikes[x])
                        if (curVis[y])
                            ok = false;
                }
                foreach (int x in lVis)
                    curVis[x] = false;
                if (ok)
                    res = num;
            }
        println(res);

    }

    private  void dfs(int at, bool[] vis, List<int>[] likes, List<int>[] disLikes, List<int> lVis, bool[] curVis, int n)
    {
        if (vis[at])
            return ;
        vis[at] = true;
        lVis.Add(at);
        foreach (int x in likes[at])
            dfs(x, vis, likes, disLikes, lVis, curVis, n);
    }

    private long go(int n, Dictionary<int, long> cache)
    {
        if (n == 1)
            return 1;
        if (cache.ContainsKey(n))
            return cache[n];
        long res = 0;
        for (int i = 1; i * i <= n; i++)
        {
            if (n % i == 0)
            {
                int a = i;
                int b = n / i;
                if (b > 1)
                    res = Math.Max(res, go(a, cache));
                if (a > 1)
                    res = Math.Max(res, go(b, cache));
            }
        }
        res += n;
        cache[n] = res;
        return res;
    }

    ////////////
    private void println(string Stringst)
    {
        Console.WriteLine(Stringst);
    }
    private void println(char charnum)
    {
        Console.WriteLine(charnum);
    }
    private void println(int Intnum)
    {
        Console.WriteLine(Intnum);
    }
    private void println(long Longnum)
    {
        Console.WriteLine(Longnum);
    }
    private void println(double Doublenum)
    {
        Console.WriteLine(Doublenum);
    }

    private void print(string Stringst)
    {
        Console.Write(Stringst);
    }
    private void print(int Intnum)
    {
        Console.Write(Intnum);
    }
    private void print(char charnum)
    {
        Console.Write(charnum);
    }
    private void print(long Longnum)
    {
        Console.Write(Longnum);
    }
    private void print(double Doublenum)
    {
        Console.Write(Doublenum);
    }

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (inputLine.Length == 0)
            readInput();

    }
    int nextInt()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return int.Parse(inputLine[inputInd++]);
    }
    long nextLong()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return long.Parse(inputLine[inputInd++]);
    }
    double nextDouble()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return double.Parse(inputLine[inputInd++]);
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        new Program().solve();
    }
}