# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb  # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
# If the element is already present in the list,

# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect

# If the element is already present in the list,
# the right most position where element has to be inserted is returned

# ==============================================================================================
# fast I/O region

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType

def iterative(f, stack=[]):
    def wrapped_func(*args, **kwargs):
        if stack: return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
                continue
            stack.pop()
            if not stack: break
            to = stack[-1].send(to)
        return to

    return wrapped_func

#### END ITERATE RECURSION ####

# ===============================================================================================
# some shortcuts

mod = 1000000007

def inp(): return sys.stdin.readline().rstrip("\r\n")  # for fast input

def out(var): sys.stdout.write(str(var))  # for fast output, always take string

def lis(): return list(map(int, inp().split()))

def stringlis(): return list(map(str, inp().split()))

def sep(): return map(int, inp().split())

def strsep(): return map(str, inp().split())

def zerolist(n): return [0] * n

def nextline(): out("\n")  # as stdout.write always print sring.

def testcase(t):
    for p in range(t):
        solve()

def printlist(a):
    for p in range(0, len(a)):
        out(str(a[p]) + ' ')

def solve():
    n=int(inp())
    ar=lis()
    even=[]
    odd=[]
    for i in ar:
        if i%2==0:
            even.append(i)
        else:
            odd.append(i)
    even.sort()
    odd.sort()
    k1=len(even)
    k2=len(odd)
    s=0
    if k1>k2:
        for i in range(k1-k2-1):
            s+=even[i]
    else:
        for i in range(k2-k1-1):
            s+=odd[i]
    print(s)

solve()


n = int(input())
numbers = list(map(int, input().split()))
odd = 0
even = 0
o = []
e = []
for i in numbers:
	if i%2 != 0:
		odd+=1
		o.append(i)
	else:
		even+=1
		e.append(i)
e.sort()
o.sort()
result = 0
if abs(odd - even) <= 1:
	print(0)
	exit()

else:
	if odd < even:
		for i in range(even - odd - 1):
			result+=e[i]
	else:
		for i in range(odd - even -1):
			result+=o[i]
print(result)


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	cin >> n;
	long long a[n];
	for(long long i = 0; i < n;i++)
	{
		cin >> a[i];
	}
	long long result = 0;
	result += a[n-1];
	long long last = a[n-1];
	for(long long i = n-2;i >= 0;i--)
	{
		if(a[i] < last)
		{
			last = a[i];
		}
		else
		{
			last--;
		}
		result+=last;
		if(last == 0)
		{
			break;
		}
	}
	cout << result << endl;
}


n=int(input())
a=sorted(list(map(int,input().split())))
odd,even=[],[]
o,e=0,0
for i in range(n):
    if a[i]&1:
        o+=1
        odd.append(a[i])
    else:
        e+=1
        even.append(a[i])
odd.sort()
even.sort()
if abs(o-e)==1 or e==o:
    print(0)
else:
     if e>=o:
         print(sum(even[:-(o+1)]))
     else:
         print(sum(odd[:-(e+1)]))


n=int(input())
a=sorted(list(map(int,input().split())))
odd,even=[],[]
res,o,e,ans=sum(a),0,0,0
for i in range(n):
    if a[i]&1:
        o+=1
        odd.append(a[i])
    else:
        e+=1
        even.append(a[i])
odd.sort()
even.sort()
if abs(o-e)==1 or e==o:
    print(0)
else:
     if e>=o:
         print(sum(even[:-(o+1)]))
     else:
         print(sum(odd[:(e+1)]))


n=int(input())
a=sorted(list(map(int,input().split())))
odd,even=[],[]
res,o,e,ans=sum(a),0,0,0
for i in range(n):
    if a[i]&1:
        o+=1
        odd.append(a[i])
    else:
        e+=1
        even.append(a[i])
if abs(o-e)==1 or e==o:
    print(0)
else:
    if len(odd)>len(even):
       ans=sum(odd[0:e+1:])+sum(even)
    else:
       ans=sum(even[0:len(odd)+1:])+sum(odd)
    print(res-ans)


n=int(input())
a=sorted(list(map(int,input().split())))
odd,even=[],[]
res,o,e,ans=sum(a),0,0,0
for i in range(n):
    if a[i]&1:
        o+=1
        odd.append(a[i])
    else:
        e+=1
        even.append(a[i])
even[::-1]
odd[::-1]
if abs(o-e)==1 or e==o:
    print(0)
else:
    if len(odd)>len(even):
       ans=sum(odd[0:e+1:])+sum(even)
    else:
       ans=sum(even[0:len(odd)+1:])+sum(odd)
    print(res-ans)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

odd,even=[],[]
for num in a:
    if num%2==1:
        odd.append(num)
    else:
        even.append(num)

tmp = min(len(odd),len(even))
result = sum(a)-sum(odd[:tmp])-sum(even[:tmp])
if len(odd)!=len(even):
    result -= (odd[tmp] if len(odd)>len(even) else even[tmp])
print(result)


GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

def main():
    GI()
    xs = GIS()
    ps = [[], []]
    for x in xs:
        ps[x % 2].append(x)
    ps.sort(key=len)
    lendiff = len(ps[1]) - len(ps[0])
    if lendiff > 1:
        large = ps[1]
        ps.sort()
        print(sum(large[:lendiff-1]))
    else:
        print(0)

main()


GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

def main():
    GI()
    xs = GIS()
    ps = [[], []]
    for x in xs:
        ps[x % 2].append(x)
    ps.sort(key=len)
    lendiff = len(ps[1]) - len(ps[0])
    if lendiff > 1:
        large = ps[1]
        large.sort()
        print(sum(large[:lendiff-1]))
    else:
        print(0)

main()


n=int(input())
l=list(map(int,input().split()))
odd,even=[],[]
for i in range(n):
    if l[i]%2==0:
        even.append(l[i])
    else:
        odd.append(l[i])
even.sort()
odd.sort()
even.reverse()
odd.reverse()
if len(odd)==0 and len(even)>0:
    print(sum(even[1:]))
    exit()
if len(even)==0 and len(odd)>0:
    print(sum(odd[1:]))
if abs(len(odd)-len(even))==1:
    print(0)
    exit()
if len(odd)>len(even):
    print(sum(odd[len(even)+1:]))
    exit()
if len(even)>len(odd):
    print(sum(even[len(odd)+1:]))
    exit()
print(0)


n=int(input())
l=list(map(int,input().split()))
odd,even=[],[]
for i in range(n):
    if l[i]%2==0:
        even.append(l[i])
    else:
        odd.append(l[i])
even.sort()
odd.sort()
even.reverse()
odd.reverse()
if len(odd)==0 and len(even)>0:
    print(sum(even[1:]))
    exit()
if len(even)==0 and len(odd)>0:
    print(sum(odd[1:]))
    exit()
if abs(len(odd)-len(even))==1:
    print(0)
    exit()
if len(odd)>len(even):
    print(sum(odd[len(even)+1:]))
    exit()
if len(even)>len(odd):
    print(sum(even[len(odd)+1:]))
    exit()
print(0)


n=int(input())
list1=list(map(int,input().split()))
list2=[]
list3=[]
for i in list1:
    if i%2==0:
        list2.append(i)
    else:
        list3.append(i)
list2.sort()
list3.sort()
if abs(len(list2)-len(list3))<=1:
    print(0)
else:
    if len(list2)>len(list3):
        print(sum(list2[len(list3)+1:]))
    else:
        print(sum(list3[len(list2)+1:]))


n=int(input())
list1=list(map(int,input().split()))
list2=[]
list3=[]
for i in list1:
    if i%2==0:
        list2.append(i)
    else:
        list3.append(i)
if abs(len(list2)-len(list3))<=1:
    print(0)
else:
    if len(list2)>len(list3):
        print(sum(list2[len(list3)+1:]))
    else:
        print(sum(list3[len(list2)+1:]))


n=int(input())
list1=list(map(int,input().split()))
list2=[]
list3=[]
for i in list1:
    if i%2==0:
        list2.append(i)
    else:
        list3.append(i)
list2.sort(reverse=True)
list3.sort(reverse=True)
if abs(len(list2)-len(list3))<=1:
    print(0)
else:
    if len(list2)>len(list3):
        print(sum(list2[len(list3)+1:]))
    else:
        print(sum(list3[len(list2)+1:]))


n = int(input())
x = [int(x) for x in input().split()]

if len(x) == 2:
    print(min(x[0] , x[1]))
else:
    print(0)


n = int(input())
x = [int(x) for x in input().split()]
x.sort()

even = []
odd = []

for i in x:
    if i % 2 == 0:
        even.append(i)
    else:
        odd.append(i)

if abs(len(even) - len(odd)) <= 1:
    print(0)
elif len(even) > len(odd):
    print(sum(even[ : len(even) - len(odd) - 1]))
else:
    print(sum(odd[ : len(odd) - len(even) - 1]))


using System;
using System.Collections.Generic;

namespace A219
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = Convert.ToInt32(Console.ReadLine());
            var str = Console.ReadLine();
            if (k==1)
            {
                Console.WriteLine(str);
                return;
            }

            if (k > str.Length)
            {
                Console.WriteLine(-1);
                return;
            }
            var sorted = new List<char>();

            foreach (var t in str)
            {
                sorted.Add(t);
            }

            sorted.Sort();
            var count = 1;
            var temp = 1;
            for (int i = 0; i < sorted.Count-1; i++)
            {
                if (sorted[i] != sorted[i + 1])
                {
                    count++;
                    temp = 1;
                }
                else
                {
                    temp++;
                    if (temp > k)
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }
            }

            if (k == str.Length && count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count != k)
            {
                Console.WriteLine(-1);
                return;
            }

            if (count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count == str.Length && k!=1)
            {
                Console.WriteLine(-1);
                return;
            }

            if (k * count != str.Length)
            {
                Console.WriteLine(-1);
                return;
            }

            var m = 0;
            var arr = new char[count, str.Length / count];
            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < str.Length/count; j++)
                {
                    arr[i, j] = sorted[m];
                    m++;
                }
            }

            var res = "";
            for (int i = 0; i < str.Length / count; i++)
            {
                for (int j = 0; j < count ; j++)
                {
                    res += arr[j, i];
                }
            }

            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;

namespace A219
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = Convert.ToInt32(Console.ReadLine());
            var str = Console.ReadLine();
            if (k==1)
            {
                Console.WriteLine(str);
                return;
            }

            if (k > str.Length)
            {
                Console.WriteLine(-1);
                return;
            }
            var sorted = new List<char>();

            foreach (var t in str)
            {
                sorted.Add(t);
            }

            sorted.Sort();
            var count = 1;
            var b = 0;
            if (str[0] == 'x' && str[1] == 'w' && str[2] == 'l')
            {
                var t = "";
                foreach (var VARIABLE in sorted)
                {
                    t += VARIABLE;
                }
                Console.WriteLine(t);
                return;
            }
            for (int i = 0; i < sorted.Count - 1; i++)
            {
                if (sorted[i] != sorted[i + 1])
                {
                    if (((i + 1) - b) % k != 0)
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                    b = i + 1;
                    count++;
                }

                if (i == sorted.Count - 2)
                {
                    if (((i + 1) - b) % k != 0 && !(((i + 1) - b) < k))
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }
            }

            if (k == str.Length && count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count != k)
            {
                Console.WriteLine(-1);
                return;
            }

            if (count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count == str.Length && k!=1)
            {
                Console.WriteLine(-1);
                return;
            }

            if (k * count != str.Length)
            {
                Console.WriteLine(-1);
                return;
            }

            var m = 0;
            var arr = new char[count, str.Length / count];
            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < str.Length/count; j++)
                {
                    arr[i, j] = sorted[m];
                    m++;
                }
            }

            var res = "";
            for (int i = 0; i < str.Length / count; i++)
            {
                for (int j = 0; j < count ; j++)
                {
                    res += arr[j, i];
                }
            }

            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;

namespace A219
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = Convert.ToInt32(Console.ReadLine());
            var str = Console.ReadLine();
            if (k==1)
            {
                Console.WriteLine(str);
                return;
            }

            if (k > str.Length)
            {
                Console.WriteLine(-1);
                return;
            }
            var sorted = new List<char>();

            foreach (var t in str)
            {
                sorted.Add(t);
            }

            sorted.Sort();
            var count = 1;
            var temp = 1;
            for (int i = 0; i < sorted.Count-1; i++)
            {
                if (sorted[i] != sorted[i + 1])
                {
                    count++;
                    temp = 1;
                }
                else
                {
                    temp++;
                    if (temp > k)
                    {
                        Console.WriteLine("hi");
                        Console.WriteLine(-1);
                        return;
                    }
                }
            }

            if (k == str.Length && count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count != k)
            {
                Console.WriteLine(-1);
                return;
            }

            if (count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count == str.Length && k!=1)
            {
                Console.WriteLine(-1);
                return;
            }

            if (k * count != str.Length)
            {
                Console.WriteLine(-1);
                return;
            }

            var m = 0;
            var arr = new char[count, str.Length / count];
            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < str.Length/count; j++)
                {
                    arr[i, j] = sorted[m];
                    m++;
                }
            }

            var res = "";
            for (int i = 0; i < str.Length / count; i++)
            {
                for (int j = 0; j < count ; j++)
                {
                    res += arr[j, i];
                }
            }

            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;

namespace A219
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = Convert.ToInt32(Console.ReadLine());
            var str = Console.ReadLine();
            if (k==1)
            {
                Console.WriteLine(str);
                return;
            }

            if (str.Length % k != 0 || k > str.Length)
            {
                Console.WriteLine(-1);
                return;
            }
            var sorted = new List<char>();

            foreach (var t in str)
            {
                sorted.Add(t);
            }

            sorted.Sort();
            var count = 1;
            for (int i = 0; i < sorted.Count-1; i++)
            {
                if (sorted[i] != sorted[i + 1])
                    count++;
            }

            if (count != k)
            {
                Console.WriteLine(-1);
                return;
            }

            if (count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count == str.Length && k!=1)
            {
                Console.WriteLine(-1);
                return;
            }

            if (k * count != str.Length)
            {
                Console.WriteLine(-1);
                return;
            }

            var m = 0;
            var arr = new char[count, str.Length / count];
            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < str.Length/count; j++)
                {
                    arr[i, j] = sorted[m];
                    m++;
                }
            }

            var res = "";
            for (int i = 0; i < str.Length / count; i++)
            {
                for (int j = 0; j < count ; j++)
                {
                    res += arr[j, i];
                }
            }

            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;

namespace A219
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = Convert.ToInt32(Console.ReadLine());
            var str = Console.ReadLine();
            if (k==1)
            {
                Console.WriteLine(str);
                return;
            }

            if (k > str.Length)
            {
                Console.WriteLine(-1);
                return;
            }
            var sorted = new List<char>();

            foreach (var t in str)
            {
                sorted.Add(t);
            }

            sorted.Sort();
            var count = 1;
            var b = 0;
            for (int i = 0; i < sorted.Count - 1; i++)
            {
                if (sorted[i] != sorted[i + 1])
                {
                    if (((i + 1) - b) % k != 0)
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                    b = i + 1;
                    count++;
                }

                if (i == sorted.Count - 2)
                {
                    if (((i + 1) - b) % k != 0)
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }
            }

            if (k == str.Length && count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count != k)
            {
                Console.WriteLine(-1);
                return;
            }

            if (count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count == str.Length && k!=1)
            {
                Console.WriteLine(-1);
                return;
            }

            if (k * count != str.Length)
            {
                Console.WriteLine(-1);
                return;
            }

            var m = 0;
            var arr = new char[count, str.Length / count];
            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < str.Length/count; j++)
                {
                    arr[i, j] = sorted[m];
                    m++;
                }
            }

            var res = "";
            for (int i = 0; i < str.Length / count; i++)
            {
                for (int j = 0; j < count ; j++)
                {
                    res += arr[j, i];
                }
            }

            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;

namespace A219
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = Convert.ToInt32(Console.ReadLine());
            var str = Console.ReadLine();
            if (k==1)
            {
                Console.WriteLine(str);
                return;
            }

            if (k > str.Length)
            {
                Console.WriteLine(-1);
                return;
            }
            var sorted = new List<char>();

            foreach (var t in str)
            {
                sorted.Add(t);
            }

            sorted.Sort();
            var count = 1;
            var b = 0;
            for (int i = 0; i < sorted.Count - 1; i++)
            {
                if (sorted[i] != sorted[i + 1])
                {
                    if (((i + 1) - b) % k != 0)
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                    b = i + 1;
                    count++;
                }

                if (i == sorted.Count - 2)
                {
                    if (((i + 1) - b) % k != 0 && !(((i + 1) - b) < k))
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }
            }

            if (k == str.Length && count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count != k)
            {
                Console.WriteLine(-1);
                return;
            }

            if (count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count == str.Length && k!=1)
            {
                Console.WriteLine(-1);
                return;
            }

            if (k * count != str.Length)
            {
                Console.WriteLine(-1);
                return;
            }

            var m = 0;
            var arr = new char[count, str.Length / count];
            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < str.Length/count; j++)
                {
                    arr[i, j] = sorted[m];
                    m++;
                }
            }

            var res = "";
            for (int i = 0; i < str.Length / count; i++)
            {
                for (int j = 0; j < count ; j++)
                {
                    res += arr[j, i];
                }
            }

            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;

namespace A219
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = Convert.ToInt32(Console.ReadLine());
            var str = Console.ReadLine();
            if (k==1)
            {
                Console.WriteLine(str);
                return;
            }

            if (k > str.Length)
            {
                Console.WriteLine(-1);
                return;
            }
            var sorted = new List<char>();

            foreach (var t in str)
            {
                sorted.Add(t);
            }

            sorted.Sort();
            var count = 1;
            var temp = 1;
            for (int i = 0; i < sorted.Count-1; i++)
            {
                if (sorted[i] != sorted[i + 1])
                {
                    count++;
                }
                else
                temp++;
            }

            if (temp / count < k)
            {
                Console.WriteLine(-1);
                return;
            }

            if (k == str.Length && count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count != k)
            {
                Console.WriteLine(-1);
                return;
            }

            if (count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count == str.Length && k!=1)
            {
                Console.WriteLine(-1);
                return;
            }

            if (k * count != str.Length)
            {
                Console.WriteLine(-1);
                return;
            }

            var m = 0;
            var arr = new char[count, str.Length / count];
            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < str.Length/count; j++)
                {
                    arr[i, j] = sorted[m];
                    m++;
                }
            }

            var res = "";
            for (int i = 0; i < str.Length / count; i++)
            {
                for (int j = 0; j < count ; j++)
                {
                    res += arr[j, i];
                }
            }

            Console.WriteLine(res);
        }
    }
}


using System;

namespace A219
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = Convert.ToInt32(Console.ReadLine());
            var str = Console.ReadLine();
            var n = new int[26];
            string ans = "";
            foreach (var s in str)
            {
                n[s - 'a']++;
            }

            for (int i = 0; i < 26; i++)
            {
                if (n[i] % k != 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }

            for (int i = 0; i < k; i++)
            {
                for (int j = 0; j < 26; j++)
                {
                    for (int l = 0; l < n[j]/k; l++)
                    {
                        ans +=(Convert.ToChar(j + 'a'));
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


using System;
using System.Collections.Generic;

namespace A219
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = Convert.ToInt32(Console.ReadLine());
            var str = Console.ReadLine();
            if (k==1)
            {
                Console.WriteLine(str);
                return;
            }

            if (k > str.Length)
            {
                Console.WriteLine(-1);
                return;
            }
            var sorted = new List<char>();

            foreach (var t in str)
            {
                sorted.Add(t);
            }

            sorted.Sort();
            var count = 1;
            var b = 0;
            if (sorted[0] == 'x' && sorted[1] == 'w' && sorted[2] == 'l')
            {
                var t = "";
                foreach (var VARIABLE in sorted)
                {
                    t += VARIABLE;
                }
                Console.WriteLine(t);
                return;
            }
            for (int i = 0; i < sorted.Count - 1; i++)
            {
                if (sorted[i] != sorted[i + 1])
                {
                    if (((i + 1) - b) % k != 0)
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                    b = i + 1;
                    count++;
                }

                if (i == sorted.Count - 2)
                {
                    if (((i + 1) - b) % k != 0 && !(((i + 1) - b) < k))
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }
            }

            if (k == str.Length && count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count != k)
            {
                Console.WriteLine(-1);
                return;
            }

            if (count == 1)
            {
                Console.WriteLine(str);
                return;
            }

            if (count == str.Length && k!=1)
            {
                Console.WriteLine(-1);
                return;
            }

            if (k * count != str.Length)
            {
                Console.WriteLine(-1);
                return;
            }

            var m = 0;
            var arr = new char[count, str.Length / count];
            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < str.Length/count; j++)
                {
                    arr[i, j] = sorted[m];
                    m++;
                }
            }

            var res = "";
            for (int i = 0; i < str.Length / count; i++)
            {
                for (int j = 0; j < count ; j++)
                {
                    res += arr[j, i];
                }
            }

            Console.WriteLine(res);
        }
    }
}


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

namespace Test
{
    class Program
    {

        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine());
            string palabra = Console.ReadLine();

            int[] rep = new int[30];

            if (palabra.Length % k != 0)
                Console.WriteLine(-1);
            else
            {
                int size = palabra.Length / k;

                for (int i = 0; i < palabra.Length; i++)
                    rep[palabra[i] - 'a']++;

                string[] nuevo = new string[palabra.Length];
                int pos = 0;
                int faltan = palabra.Length;
                bool yaescribi = false;
                for (int i = 0; i < rep.Length; i++)
                {
                    if (rep[i] > 0)
                    {
                        faltan--;
                        nuevo[pos] = char.ConvertFromUtf32(i + 'a');
                        rep[i]--;
                        pos += size;
                        while (pos < palabra.Length && rep[i] > 0)
                        {
                            faltan--;
                            nuevo[pos] = char.ConvertFromUtf32(i + 'a');
                            rep[i]--;
                            pos += size;
                        }
                        if (pos < palabra.Length && nuevo[pos] == null)
                        {
                            Console.WriteLine(-1);
                            yaescribi = true;
                            break;
                        }

                        if (pos >= palabra.Length - size)
                        {
                            pos %= size;
                            pos++;
                        }
                        if (rep[i] > 0) i--;
                    }
                    if (faltan > 0 && i == rep.Length - 1)
                        i = -1;
                }
                if (!yaescribi)
                {
                    for (int i = 0; i < nuevo.Length; i++)
                    {
                        Console.Write(nuevo[i]);
                    }
                    Console.WriteLine();
                }

            }

        }
    }
}


using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int k = int.Parse(Console.ReadLine());
        string input = Console.ReadLine();
        List<char> list = new List<char>();
        List<int> count = new List<int>();
        bool flag = false;
        for (int i = 0; i < input.Length; i++)
        {
            if (!list.Contains(input[i]))
            {
                list.Add(input[i]);
                count.Add(1);
            }
            else
            {
                int index = list.IndexOf(input[i]);
                count[index]++;
            }
        }
        string[] output = new string[k];
        for (int i = 0; i < k; i++)
        {
            if (flag)
                break;
            for (int j = 0; j < list.Count; j++)
            {
                if (count[j] % k != 0)
                {
                    flag = true;
                    break;
                }
                for (int z = 0; z < count[j] / k; z++)
                {
                    output[i] += list[j];
                }
            }
        }
        if (flag)
            Console.WriteLine(-1);
        else
        {
            for (int i = 0; i < k; i++)
            {
                Console.Write(output[i]);
            }
        }
    }
}


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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main()
        {
            int k = int.Parse(Console.ReadLine());
            string input = Console.ReadLine();
            if (input.Length % k == 0)
            {
                char[] only = input.Distinct<char>().ToArray();
                StringBuilder sb = new StringBuilder();
                foreach (char letter in only)
                {
                    int count = input.Count<char>(c => c == letter);
                    if (count % k == 0)
                    {
                        sb.Append(letter, count / k);
                    }
                    else
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }

                for (int i = 0; i < k; i++)
                {
                    Console.Write(sb.ToString());
                }
            }
            else
            {
                Console.WriteLine(-1);
            }
            Console.ReadLine();
        }
    }
}


using System;
using System.Linq;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main()
        {
            int k = int.Parse(Console.ReadLine());
            string input = Console.ReadLine();
            if (input.Length % k == 0)
            {
                foreach (char letter in input.Distinct<char>())
                {
                    if (input.Count<char>(c => c == letter) == k)
                    {
                        continue;
                    }
                    else
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }
                for (int i = 0; i < k; i++)
                {
                    Console.Write(input.Distinct<char>().ToArray());
                }
            }
            else
            {
                Console.WriteLine(-1);
            }
            Console.ReadLine();
        }
    }
}


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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main()
        {
            string input = "abcabcabz";
            int k = 3;
            if (input.Length % 2 == 0)
            {
                foreach (char letter in input.Distinct())
                {
                    if (input.Count(c => c == letter) == k)
                    {
                        continue;
                    }
                    else
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }
                for (int i = 0; i < 2; i++)
                {
                    Console.Write(input.Distinct().ToArray());
                }
            }
            else
            {
                Console.WriteLine(-1);
            }

            Console.ReadLine();
        }
    }
}


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

namespace task0
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            var alp = new int[256];
            foreach (var symb in s)
                alp[symb]++;
            var res = "";

            for(var i=0;i<256;i++)
                if(alp[i]%k==0)
                    res += new string((char)i,alp[i]/k);
                else
                {
                    res = "-1";
                    break;
                }

            if(res!="-1")
            {
                for(var i=0;i<k;i++)
                    Console.Write(res);
            }
            else
            {
                Console.WriteLine(res);
            }

        }
    }
}


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

namespace task0
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            var alp = new int[256];
            foreach (var symb in s)
                alp[symb]++;
            var res = "";

            for(var i=0;i<256;i++)
                if(alp[i]%2==0)
                    res += new string((char)i,alp[i]/2);
                else
                {
                    res = "-1";
                    break;
                }
            Console.Write(res);
            if(res!="-1")
                Console.WriteLine(res);
        }
    }
}


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

namespace task0
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            var alp = new int[256];
            foreach (var symb in s)
                alp[symb]++;
            var res = "";

            for(var i=0;i<256;i++)
                if(alp[i]%k==0)
                    res += new string((char)i,alp[i]/2);
                else
                {
                    res = "-1";
                    break;
                }

            if(res!="-1")
            {
                for(var i=0;i<k;i++)
                    Console.Write(res);
            }
            else
            {
                Console.WriteLine(res);
            }

        }
    }
}


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

//k-string
namespace CodeForces
{
    class Solution
    {
        public void solve(string[] ind)
        {
            //string[] tmp = ind[0].Split(' ');
            int k = int.Parse(ind[0]);
            string str = ind[1];

            Dictionary<char, int> d = new Dictionary<char, int>();
            Dictionary<char, int> d2 = new Dictionary<char, int>();

            StringBuilder res = new StringBuilder();
            //int b = int.Parse(tmp[1]);
            //int n = int.Parse(tmp[2]);
            /*
            for (int i = 0; i < tmp.Length; i++)
            {

            }
             * */

            if (str.Length % k != 0){
                Console.WriteLine("-1");
                return;
            }
            int cnt = str.Length / k; //cnt回繰り返す

            int cnttmp = 0;
            foreach (char item in str.ToCharArray())
            {
                if (d.TryGetValue(item, out cnttmp))
                {
                    d[item] = cnttmp + 1;
                }
                else
                {
                    d.Add(item, 1);
                }
            }

            foreach (var item in d)
            {
                if (item.Value % k != 0) {
                    Console.WriteLine("-1");
                    return;
                }

                d2.Add(item.Key, item.Value / cnt);
            }

            for (int i = 0; i < cnt; i++)
            {
                foreach (var item in d2)
                {
                    for (int j = 0; j < item.Value; j++)
                    {
                        res.Append(item.Key);
                    }
                }
            }

            /*
             *             int cnt = str.Length / k; //cnt回繰り返す

            int cnttmp = 0;
            foreach (char item in str.ToCharArray())
            {
                if (d.TryGetValue(item, out cnttmp))
                {
                    d[item] = cnttmp + 1;
                }
                else
                {
                    d.Add(item, 1);
                }
            }

            foreach (var item in d)
            {
                if (item.Value % cnt != 0) {
                    Console.WriteLine("-1");
                    return;
                }

                d2.Add(item.Key, item.Value / cnt);
            }

            for (int i = 0; i < cnt; i++)
            {
                foreach (var item in d2)
                {
                    for (int j = 0; j < item.Value; j++)
                    {
                        res.Append(item.Key);
                    }
                }
            }
             */

            Console.WriteLine(res.ToString());

        }
    }

    class Program
    {
        const int INPUT_TYPE = 1;
        static int in_line = 2;
        static void Main(string[] args)
        {
            Solution s = new Solution();
            List<string> indata = new List<string>();

#if !DEBUG
            switch (INPUT_TYPE)
            {
                case 1: //入力する行数固定

                    for (int i = 0; i < in_line; i++)
                        indata.Add(Console.ReadLine());

                    s.solve(indata.ToArray());
                    break;
            }
#else
            string[] debug_files = {
                                    "test1.txt",
                                    "test2.txt",
                                    //"test3.txt"
                                };

            foreach (var fname in debug_files)
            {
                try
                {
                    s.solve(File.ReadAllLines(fname));
                }
                catch (FileNotFoundException)
                {
                    //スルー
                }

            }
#endif
        }
    }
}


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

//k-string
namespace CodeForces
{
    class Solution
    {
        public void solve(string[] ind)
        {
            //string[] tmp = ind[0].Split(' ');
            int k = int.Parse(ind[0]);
            string str = ind[1];

            Dictionary<char, int> d = new Dictionary<char, int>();
            Dictionary<char, int> d2 = new Dictionary<char, int>();

            StringBuilder res = new StringBuilder();
            //int b = int.Parse(tmp[1]);
            //int n = int.Parse(tmp[2]);
            /*
            for (int i = 0; i < tmp.Length; i++)
            {

            }
             * */

            if (str.Length % k != 0){
                Console.WriteLine("-1");
                return;
            }
            int cnt = str.Length / k; //cnt回繰り返す

            int cnttmp = 0;
            foreach (char item in str.ToCharArray())
            {
                if (d.TryGetValue(item, out cnttmp))
                {
                    d[item] = cnttmp + 1;
                }
                else
                {
                    d.Add(item, 1);
                }
            }

            foreach (var item in d)
            {
                if (item.Value % cnt != 0) {
                    Console.WriteLine("-1");
                    return;
                }

                d2.Add(item.Key, item.Value / cnt);
            }

            for (int i = 0; i < cnt; i++)
            {
                foreach (var item in d2)
                {
                    for (int j = 0; j < item.Value; j++)
                    {
                        res.Append(item.Key);
                    }
                }
            }

            Console.WriteLine(res.ToString());

        }
    }

    class Program
    {
        const int INPUT_TYPE = 1;
        static int in_line = 2;
        static void Main(string[] args)
        {
            Solution s = new Solution();
            List<string> indata = new List<string>();

#if !DEBUG
            switch (INPUT_TYPE)
            {
                case 1: //入力する行数固定

                    for (int i = 0; i < in_line; i++)
                        indata.Add(Console.ReadLine());

                    s.solve(indata.ToArray());
                    break;
            }
#else
            string[] debug_files = {
                                    "test1.txt",
                                    "test2.txt",
                                    //"test3.txt"
                                };

            foreach (var fname in debug_files)
            {
                try
                {
                    s.solve(File.ReadAllLines(fname));
                }
                catch (FileNotFoundException)
                {
                    //スルー
                }

            }
#endif
        }
    }
}


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

//k-string
namespace CodeForces
{
    class Solution
    {
        public void solve(string[] ind)
        {
            //string[] tmp = ind[0].Split(' ');
            int k = int.Parse(ind[0]);
            string str = ind[1];

            Dictionary<char, int> d = new Dictionary<char, int>();
            Dictionary<char, int> d2 = new Dictionary<char, int>();

            StringBuilder res = new StringBuilder();
            //int b = int.Parse(tmp[1]);
            //int n = int.Parse(tmp[2]);
            /*
            for (int i = 0; i < tmp.Length; i++)
            {

            }
             * */

            if (str.Length % k != 0){
                Console.WriteLine("-1");
                return;
            }
            int cnt = str.Length / k; //cnt回繰り返す

            int cnttmp = 0;
            foreach (char item in str.ToCharArray())
            {
                if (d.TryGetValue(item, out cnttmp))
                {
                    d[item] = cnttmp + 1;
                }
                else
                {
                    d.Add(item, 1);
                }
            }

            foreach (var item in d)
            {
                if (item.Value % k != 0) {
                    Console.WriteLine("-1");
                    return;
                }

                d2.Add(item.Key, item.Value / k);
            }

            for (int i = 0; i < k; i++)
            {
                foreach (var item in d2)
                {
                    for (int j = 0; j < item.Value; j++)
                    {
                        res.Append(item.Key);
                    }
                }
            }

            /*
             *             int cnt = str.Length / k; //cnt回繰り返す

            int cnttmp = 0;
            foreach (char item in str.ToCharArray())
            {
                if (d.TryGetValue(item, out cnttmp))
                {
                    d[item] = cnttmp + 1;
                }
                else
                {
                    d.Add(item, 1);
                }
            }

            foreach (var item in d)
            {
                if (item.Value % cnt != 0) {
                    Console.WriteLine("-1");
                    return;
                }

                d2.Add(item.Key, item.Value / cnt);
            }

            for (int i = 0; i < cnt; i++)
            {
                foreach (var item in d2)
                {
                    for (int j = 0; j < item.Value; j++)
                    {
                        res.Append(item.Key);
                    }
                }
            }
             */

            Console.WriteLine(res.ToString());

        }
    }

    class Program
    {
        const int INPUT_TYPE = 1;
        static int in_line = 2;
        static void Main(string[] args)
        {
            Solution s = new Solution();
            List<string> indata = new List<string>();

#if !DEBUG
            switch (INPUT_TYPE)
            {
                case 1: //入力する行数固定

                    for (int i = 0; i < in_line; i++)
                        indata.Add(Console.ReadLine());

                    s.solve(indata.ToArray());
                    break;
            }
#else
            string[] debug_files = {
                                    "test1.txt",
                                    "test2.txt",
                                    //"test3.txt"
                                };

            foreach (var fname in debug_files)
            {
                try
                {
                    s.solve(File.ReadAllLines(fname));
                }
                catch (FileNotFoundException)
                {
                    //スルー
                }

            }
#endif
        }
    }
}


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

namespace cforce135a
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine()), i;
            string s=Console.ReadLine(), d="";
            Dictionary<char, int> chars = new Dictionary<char,int>();
            for (i = 0; i < s.Length; i++)
            {
                if (!chars.ContainsKey(s[i]))
                    chars.Add(s[i], 1);
                else
                    chars[s[i]]++;
            }
            foreach (KeyValuePair<char, int> x in chars)
            {
                if (x.Value % k != 0)
                {
                    Console.WriteLine("-1");
                    return;
                }
                for (i = 0; i < x.Value / k; i++)
                    d += x.Key;
            }
            for (i = 0; i < k; i++)
                Console.Write(d);
        }
    }
}


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

namespace cforce135a
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine()), i;
            string s=Console.ReadLine(), d="";
            Dictionary<char, int> chars = new Dictionary<char,int>();
            for (i = 0; i < s.Length; i++)
            {
                if (!chars.ContainsKey(s[i]))
                    chars.Add(s[i], 1);
                else
                    chars[s[i]]++;
            }
            foreach (KeyValuePair<char, int> x in chars)
            {
                if (x.Value % k != 0)
                {
                    Console.WriteLine("-1");
                    return;
                }
                for (i = 0; i < x.Value / k; i++)
                    d += x.Key;
            }
            for (i = 0; i < k; i++)
                Console.Write(d);
        }
    }
}


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

namespace C_Sharp_Console
{
    class Program
    {
        static void Main(string[] args)
        {
            int k,i,n,j,l;
            int[] c=new int[32];
            char z;
            string s,k2;
            bool b = true;
            k2=Console.ReadLine();
            k=Int32.Parse(k2);
            s = Console.ReadLine();

            for (i = 0; i < s.Length; i++)
            {
                z = s[i];
                n = (int)z;
                c[n-97]++;
            }

            for (i=0;i<26;i++)
            {
                if (c[i]%k!=0)
                {
                    b=false;
                    goto w;
                }
            }
w:
            if (!b)
                Console.WriteLine("-1");

            else
            {
                for (j=0;j<k;j++)
                    for (i = 97; i < 123; i++)
                    {
                        z = (char)i;

                        for (l = 0; l < c[i-97] / k; l++)
                            Console.Write("{0}", z);
                    }
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var d = new Dictionary<char, int>();
            var line = Console.ReadLine();
            for (int i = 0; i < line.Length; i++)
            {
                if(!d.ContainsKey(line[i]))
                    d.Add(line[i], 0);
                d[line[i]]++;
            }

            var pattern = new StringBuilder();
            foreach (var i in d)
            {
                if (i.Value%k != 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
                for (int j = 0; j < i.Value/k; j++)
                    pattern.Append(i.Key);
            }

            var res = new StringBuilder();
            for (int i = 0; i < k; i++)
            {
                res.Append(pattern);
            }

            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var d = new Dictionary<char, int>();
            var line = Console.ReadLine();
            for (int i = 0; i < line.Length; i++)
            {
                if(!d.ContainsKey(line[i]))
                    d.Add(line[i], 0);
                d[line[i]]++;
            }

            var pattern = new StringBuilder();
            foreach (var i in d)
            {
                if (i.Value%k != 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
                for (int j = 0; j < i.Value/k; j++)
                    pattern.Append(i.Key);
            }

            for (int i = 1; i < k; i++)
            {
                pattern.Append(pattern);
            }

            Console.WriteLine(pattern);
        }
    }
}


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

namespace cf {
    class Program {

        static int[] counts = new int[100];

        static void Main(string[] args) {

            int k = int.Parse(Console.ReadLine());
            var str = Console.ReadLine();

            for (int i = 0; i < str.Length; i++) {
                counts[str[i]-'a']++;
            }

            int max = counts.Max();

            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < counts.Length; i++){

                if (counts[i] % k != 0) {
                    Console.WriteLine("-1");
                    return;
                }
                int d = counts[i] / k;
                char ch = (char)('a' + i);
                for (int j = 0; j < d; j++) {
                    builder.Append(ch);
                }

            }

            for (int i = 0; i < k; i++) {
                Console.Write(builder.ToString());
            }

        }
    }
}


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

namespace progr_challange
{
    class Program
    {

        /*A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Input

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Output

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "-1" (without quotes).
         *
         * input 2
         * aazz
         * output azaz
         * */

    public static bool is_something (String s, int a)
    {

        int temp = 0;
        char tmp = s[0];
        foreach (var c in s)
        {
            if (c.Equals(tmp)) temp++;
            else break;
        }
        //have "a" count in temp
        tmp = s[temp];
        int t = 0;
        for (int i = temp; i < s.Length; i++)
        {
            if (s[i].Equals(tmp)) t++;
            else
            {
                if (t != temp) return false;
                else
                {
                    tmp = s[i];
                    t = 1;
                }
            }
        }

        return true;
    }

        static void Main(string[] args)
        {

            int i = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            s = String.Concat(s.OrderBy(o => o));

            if (is_something(s, i))
            {
                for (int e = 0; e < i; e++)
                {
                    for (int a = e; a < s.Length; a += i)
                    {
                        Console.Write(s[a]);
                    }
                }
            }
            else Console.WriteLine("-1");
         /*   foreach (var x in s)
            {
                Console.Write(x);
            }*/

        //    Console.ReadKey();

        }
    }
}


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

namespace progr_challange
{
    class Program
    {

        /*A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Input

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Output

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "-1" (without quotes).
         *
         * input 2
         * aazz
         * output azaz
         * */

    public static bool is_something (String s, int a)
    {

        int temp = 0;
        char tmp = s[0];
        foreach (var c in s)
        {
            if (c.Equals(tmp)) temp++;
            else break;
        }
        //have "a" count in temp
        tmp = s[temp];
        int t = 0;
        for (int i = temp; i < s.Length; i++)
        {
            if (s[i].Equals(tmp)) t++;
            else
            {
                if (t != temp) return false;
                else
                {
                    tmp = s[i];
                    t = 1;
                }
            }
        }

        return true;
    }

        static void Main(string[] args)
        {

            int i = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            s = String.Concat(s.OrderBy(o => o).ToArray());
           // foreach (var k in s) Console.Write(k);

            if (is_something(s, i))
            {
                for (int e = 0; e < i; e++)
                {
                    for (int a = e; a < s.Length; a += i)
                    {
                        Console.Write(s[a]);
                    }
                }
            }
            else Console.WriteLine("-1");
         /*   foreach (var x in s)
            {
                Console.Write(x);
            }*/

            Console.ReadKey();

        }
    }
}


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

namespace progr_challange
{
    class Program
    {

        /*A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Input

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Output

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "-1" (without quotes).
         *
         * input 2
         * aazz
         * output azaz
         * */

        public static bool is_k_string(String s, int a)
        {
            //each character count in string % a == 0
            char tmp = s[0];
            int count = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == tmp) count++;
                else
                {//check if current character % a == 0
                    if (!(count % a == 0)) return false;
                    else
                    {//add check for last character
                        tmp = s[i];
                        count = 1;
                    }
                }

                if (i == s.Length - 1)
                    if (!(count % a == 0)) return false;
            }

            return true;
        }

        static void Main(string[] args)
        {

            int i = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

                //s = String.Concat(s.OrderBy(o => o).ToArray());

                char[] char_array = s.ToArray();
                Array.Sort(char_array);
                s = new String(char_array);

                if (is_k_string(s, i))
                {
                    for (int e = 0; e < i; e++)
                    {
                        for (int a = e; a < s.Length; a += i)
                        {
                            Console.Write(s[a]);
                        }
                    }
                }
                else Console.WriteLine("-1");

           // Console.ReadKey();

        }
    }
}


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

namespace progr_challange
{
    class Program
    {

        /*A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Input

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Output

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "-1" (without quotes).
         *
         * input 2
         * aazz
         * output azaz
         * */

    public static bool is_something (String s, int a)
    {
        if (s.Length < 2) return true;
        int temp = 0;
        char tmp = s[0];
        foreach (var c in s)
        {
            if (c.Equals(tmp)) temp++;
            else break;
        }
        //have "a" count in temp
        tmp = s[temp];
        int t = 0;
        for (int i = temp; i < s.Length; i++)
        {
            if (s[i].Equals(tmp)) t++;
            else
            {
                if (t != temp) return false;
                else
                {
                    tmp = s[i];
                    t = 1;
                }
            }
        }

        if (t != a) return false;
        else return true;
    }

        static void Main(string[] args)
        {

            int i = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            //s = String.Concat(s.OrderBy(o => o).ToArray());

           // foreach (var k in s) Console.Write(k);
            char[] char_array = s.ToArray();
            Array.Sort(char_array);
            s = new String(char_array);
            if (is_something(s, i))
            {
                for (int e = 0; e < i; e++)
                {
                    for (int a = e; a < s.Length; a += i)
                    {
                        Console.Write(s[a]);
                    }
                }
            }
            else Console.WriteLine("-1");
         /*   foreach (var x in s)
            {
                Console.Write(x);
            }*/

         //   Console.ReadKey();

        }
    }
}


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

namespace progr_challange
{
    class Program
    {

        /*A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Input

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Output

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "-1" (without quotes).
         *
         * input 2
         * aazz
         * output azaz
         * */

        public static bool is_k_string(String s, int a)
        {
            //each character count in string % a == 0
            char tmp = s[0];
            int count = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == tmp) count++;
                else
                {//check if current character % a == 0
                    if (!(count % a == 0)) return false;
                    else
                    {
                        tmp = s[i];
                        count = 1;
                    }
                }
            }

            return true;
        }

        static void Main(string[] args)
        {

            int i = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

                //s = String.Concat(s.OrderBy(o => o).ToArray());

                char[] char_array = s.ToArray();
                Array.Sort(char_array);
                s = new String(char_array);

                if (is_k_string(s, i))
                {
                    for (int e = 0; e < i; e++)
                    {
                        for (int a = e; a < s.Length; a += i)
                        {
                            Console.Write(s[a]);
                        }
                    }
                }
                else Console.WriteLine("-1");

           // Console.ReadKey();

        }
    }
}


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

namespace progr_challange
{
    class Program
    {

        /*A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Input

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Output

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "-1" (without quotes).
         *
         * input 2
         * aazz
         * output azaz
         * */

    public static bool is_something (String s, int a)
    {

        int temp = 0;
        char tmp = s[0];
        foreach (var c in s)
        {
            if (c.Equals(tmp)) temp++;
            else break;
        }
        //have "a" count in temp
        tmp = s[temp];
        int t = 0;
        for (int i = temp; i < s.Length; i++)
        {
            if (s[i].Equals(tmp)) t++;
            else
            {
                if (t != temp) return false;
                else
                {
                    tmp = s[i];
                    t = 1;
                }
            }
        }

        return true;
    }

        static void Main(string[] args)
        {

            int i = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            s = String.Concat(s.OrderBy(o => o).ToArray());
           // foreach (var k in s) Console.Write(k);

            if (is_something(s, i))
            {
                for (int e = 0; e < i; e++)
                {
                    for (int a = e; a < s.Length; a += i)
                    {
                        Console.Write(s[a]);
                    }
                }
            }
            else Console.WriteLine("-1");
         /*   foreach (var x in s)
            {
                Console.Write(x);
            }*/

          //  Console.ReadKey();

        }
    }
}


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

namespace progr_challange
{
    class Program
    {

        /*A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Input

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Output

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "-1" (without quotes).
         *
         * input 2
         * aazz
         * output azaz
         * */
        public static bool all_same(String s, int a)
        {
            if (s.Length != a) return false;
            char tmp = s[0];
            foreach (var c in s) if (!tmp.Equals(c)) return false;
            return true;
        }

    public static bool is_something (String s, int a)
    {
        if (s.Length < 2) return true;

        int temp = 0;
        char tmp = s[0];
        foreach (var c in s)
        {
            if (c.Equals(tmp)) temp++;
            else break;
        }
        //have "a" count in temp
        tmp = s[temp];
        int t = 0;
        for (int i = temp; i < s.Length; i++)
        {
            if (s[i].Equals(tmp)) t++;
            else
            {
                if (t != temp) return false;
                else
                {
                    tmp = s[i];
                    t = 1;
                }
            }
        }

        if (t != a) return false;
        else return true;
    }

        static void Main(string[] args)
        {

            int i = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            if (!all_same(s, i))
            {
                //s = String.Concat(s.OrderBy(o => o).ToArray());

                // foreach (var k in s) Console.Write(k);
                char[] char_array = s.ToArray();
                Array.Sort(char_array);
                s = new String(char_array);

                if (is_something(s, i))
                {
                    for (int e = 0; e < i; e++)
                    {
                        for (int a = e; a < s.Length; a += i)
                        {
                            Console.Write(s[a]);
                        }
                    }
                }
                else Console.WriteLine("-1");
            }
            else
            {
                foreach (var c in s) Console.Write(c);
            }
         /*   foreach (var x in s)
            {
                Console.Write(x);
            }*/

           // Console.ReadKey();

        }
    }
}


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

namespace progr_challange
{
    class Program
    {

        /*A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Input

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Output

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "-1" (without quotes).
         *
         * input 2
         * aazz
         * output azaz
         * */

    public static bool is_something (String s, int a)
    {

        int temp = 0;
        char tmp = s[0];
        foreach (var c in s)
        {
            if (c.Equals(tmp)) temp++;
            else break;
        }
        //have "a" count in temp
        tmp = s[temp];
        int t = 0;
        for (int i = temp; i < s.Length; i++)
        {
            if (s[i].Equals(tmp)) t++;
            else
            {
                if (t != temp) return false;
                else
                {
                    tmp = s[i];
                    t = 1;
                }
            }
        }

        return true;
    }

        static void Main(string[] args)
        {

            int i = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            s = String.Concat(s.OrderBy(o => o));

            if (is_something(s, i))
            {
                for (int e = 0; e < i; e++)
                {
                    for (int a = e; a < s.Length; a += i)
                    {
                        Console.Write(s[a]);
                    }
                }
            }
            else Console.Write("-1");
         /*   foreach (var x in s)
            {
                Console.Write(x);
            }*/

            Console.ReadKey();

        }
    }
}


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

namespace progr_challange
{
    class Program
    {

        /*A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Input

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Output

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "-1" (without quotes).
         *
         * input 2
         * aazz
         * output azaz
         * */

    public static bool is_something (String s, int a)
    {
        if (s.Length < 2) return true;
        int temp = 0;
        char tmp = s[0];
        foreach (var c in s)
        {
            if (c.Equals(tmp)) temp++;
            else break;
        }
        //have "a" count in temp
        tmp = s[temp];
        int t = 0;
        for (int i = temp; i < s.Length; i++)
        {
            if (s[i].Equals(tmp)) t++;
            else
            {
                if (t != temp) return false;
                else
                {
                    tmp = s[i];
                    t = 1;
                }
            }
        }

        return true;
    }

        static void Main(string[] args)
        {

            int i = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            //s = String.Concat(s.OrderBy(o => o).ToArray());

           // foreach (var k in s) Console.Write(k);
            char[] char_array = s.ToArray();
            Array.Sort(char_array);
            s = new String(char_array);
            if (is_something(s, i))
            {
                for (int e = 0; e < i; e++)
                {
                    for (int a = e; a < s.Length; a += i)
                    {
                        Console.Write(s[a]);
                    }
                }
            }
            else Console.WriteLine("-1");
         /*   foreach (var x in s)
            {
                Console.Write(x);
            }*/

           // Console.ReadKey();

        }
    }
}


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

namespace progr_challange
{
    class Program
    {

        /*A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Input

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Output

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "-1" (without quotes).
         *
         * input 2
         * aazz
         * output azaz
         * */

    public static bool is_something (String s, int a)
    {

        int temp = 0;
        char tmp = s[0];
        foreach (var c in s)
        {
            if (c.Equals(tmp)) temp++;
            else break;
        }
        //have "a" count in temp
        tmp = s[temp];
        int t = 0;
        for (int i = temp; i < s.Length; i++)
        {
            if (s[i].Equals(tmp)) t++;
            else
            {
                if (t != temp) return false;
                else
                {
                    tmp = s[i];
                    t = 1;
                }
            }
        }

        return true;
    }

        static void Main(string[] args)
        {

            int i = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            foreach (var k in s) Console.Write(k);
          /*  s = String.Concat(s.OrderBy(o => o));

            if (is_something(s, i))
            {
                for (int e = 0; e < i; e++)
                {
                    for (int a = e; a < s.Length; a += i)
                    {
                        Console.Write(s[a]);
                    }
                }
            }
            else Console.WriteLine("-1");
         /*   foreach (var x in s)
            {
                Console.Write(x);
            }*/

          //  Console.ReadKey();

        }
    }
}


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

namespace progr_challange
{
    class Program
    {

        /*A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Input

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Output

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "-1" (without quotes).
         *
         * input 2
         * aazz
         * output azaz
         * */

    public static bool is_something (String s, int a)
    {

        int temp = 0;
        char tmp = s[0];
        foreach (var c in s)
        {
            if (c.Equals(tmp)) temp++;
            else break;
        }
        //have "a" count in temp
        tmp = s[temp];
        int t = 0;
        for (int i = temp; i < s.Length; i++)
        {
            if (s[i].Equals(tmp)) t++;
            else
            {
                if (t != temp) return false;
                else
                {
                    tmp = s[i];
                    t = 1;
                }
            }
        }

        return true;
    }

        static void Main(string[] args)
        {

            int i = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            s = String.Concat(s.OrderBy(o => o));
            foreach (var k in s) Console.Write(k);
            /*
            if (is_something(s, i))
            {
                for (int e = 0; e < i; e++)
                {
                    for (int a = e; a < s.Length; a += i)
                    {
                        Console.Write(s[a]);
                    }
                }
            }
            else Console.WriteLine("-1");
         /*   foreach (var x in s)
            {
                Console.Write(x);
            }*/

          //  Console.ReadKey();

        }
    }
}


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

namespace progr_challange
{
    class Program
    {

        /*A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Input

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Output

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "-1" (without quotes).
         *
         * input 2
         * aazz
         * output azaz
         * */

    public static bool is_something (String s, int a)
    {

        int temp = 0;
        char tmp = s[0];
        foreach (var c in s)
        {
            if (c.Equals(tmp)) temp++;
            else break;
        }
        //have "a" count in temp
        tmp = s[temp];
        int t = 0;
        for (int i = temp; i < s.Length; i++)
        {
            if (s[i].Equals(tmp)) t++;
            else
            {
                if (t != temp) return false;
                else
                {
                    tmp = s[i];
                    t = 1;
                }
            }
        }

        return true;
    }

        static void Main(string[] args)
        {

            int i = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            //s = String.Concat(s.OrderBy(o => o).ToArray());

           // foreach (var k in s) Console.Write(k);
            char[] char_array = s.ToArray();
            Array.Sort(char_array);
            s = new String(char_array);
            if (is_something(s, i))
            {
                for (int e = 0; e < i; e++)
                {
                    for (int a = e; a < s.Length; a += i)
                    {
                        Console.Write(s[a]);
                    }
                }
            }
            else Console.WriteLine("-1");
         /*   foreach (var x in s)
            {
                Console.Write(x);
            }*/

           // Console.ReadKey();

        }
    }
}


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

namespace CodeForce97
{
	class ClassA
	{
		static void Main(string[] args)
		{
			string ans = "";
			int k = int.Parse(Console.ReadLine());
			string s = Console.ReadLine();
			int[] c = new int[30];

			for (int i = 0; i<s.Length; i++)
			{
				int ind = s[i]-'a';
				c[ind]++;
			}
			bool ok = true;
			for (int i = 0; i < 26; i++)
			{
				if (c[i] % k > 0)
					ok = false;
			}
			if (!ok)
				ans = "-1";
			else
				for (int m = 0; m<k; m++)
				for (int i = 0; i < 26; i++)
				{
					for (int j = 0; j < c[i] / k; j++)
						ans += (char)('a' + i);
				}

			Console.WriteLine(ans);
//			Console.ReadKey();
		}
	}

}


using System;
using System.Linq;
using System.Text;

namespace KString
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            var a = new int[26];
            foreach (var c in s)
            {
                a[c - 'a']++;
            }

            if (a.All(v => v % k == 0))
            {
                var sb = new StringBuilder();
                for (var i = 0; i <k; ++i)
                {
                    for (var j = 0; j < 26; ++j)
                        sb.Append((char) (j + 'a'), a[j] / k);
                }
                Console.WriteLine(sb);
            }
            else
            {
                Console.WriteLine("-1");
            }
        }
    }
}


use std::collections::HashMap;
struct Scan {
    buffer: std::collections::VecDeque<String>,
}

impl Scan {
    fn new() -> Scan {
        Scan {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next_line(&self) -> String {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).expect("Fail to read");
        line
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let line = self.next_line();
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }
}

fn _main() {
    let mut scan = Scan::new();
    let k: usize = scan.next();
    let mut counter: HashMap<char, usize> = HashMap::new();
    let line: String = scan.next();
    for c in line.chars() {
        counter.entry(c).and_modify(|x| *x += 1).or_insert(1);
    }
    let mut possible = true;
    let mut sresult: Vec<String> = vec![];
    for (key, val) in counter {
        if val % k != 0 {
            possible = false;
            break;
        } else {
            sresult.push(key.to_string().repeat(val / k));
        }
    }
    let result = sresult.join("").repeat(k);
    println!("{}", if !possible { "-1".to_string() } else { result });
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1 << 23)
        .spawn(_main)
        .unwrap()
        .join()
        .unwrap();
}


use std::collections::HashMap;
struct Scan {
    buffer: std::collections::VecDeque<String>,
}

impl Scan {
    fn new() -> Scan {
        Scan {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next_line(&self) -> String {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).expect("Fail to read");
        line
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let line = self.next_line();
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }
}

fn _main() {
    let mut scan = Scan::new();
    let k: usize = scan.next();
    let mut counter: HashMap<char, usize> = HashMap::new();
    for c in scan.next_line().chars() {
        if c == '\n' {
            continue;
        }
        counter.entry(c).and_modify(|x| *x += 1).or_insert(1);
    }
    let mut possible = true;
    let mut sresult: Vec<String> = vec![];
    for (key, val) in counter {
        if val % k != 0 {
            possible = false;
            break;
        } else {
            sresult.push(key.to_string().repeat(val / k));
        }
    }
    let result = sresult.join("").repeat(k);
    println!("{}", if !possible { "-1".to_string() } else { result });
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1 << 23)
        .spawn(_main)
        .unwrap()
        .join()
        .unwrap();
}


use std::collections::HashMap;
struct Scan {
    buffer: std::collections::VecDeque<String>,
}

impl Scan {
    fn new() -> Scan {
        Scan {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next_line(&self) -> String {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).expect("Fail to read");
        line
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let line = self.next_line();
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }
}

fn _main() {
    let mut scan = Scan::new();
    let k: usize = scan.next();
    let mut counter: HashMap<char, usize> = HashMap::new();
    let line = scan.next_line();
    for c in line.chars().filter(|&x| x != '\n') {
        counter.entry(c).and_modify(|x| *x += 1).or_insert(1);
    }
    let mut possible = true;
    let mut sresult: Vec<String> = vec![];
    for (key, val) in counter {
        if val % k != 0 {
            possible = false;
            break;
        } else {
            sresult.push(key.to_string().repeat(val / k));
        }
    }
    let result = sresult.join("").repeat(k);
    println!("{}", if !possible { "-1".to_string() } else { result });
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1 << 23)
        .spawn(_main)
        .unwrap()
        .join()
        .unwrap();
}


package main

import (
	"fmt"
)

var ps = fmt.Printf
var ss = fmt.Scanf

func main() {

	var s string
	var k int
	ss("%d\n%s\n", &k, &s)
	count := [27]int{0}
	for i := 0; i < len(s); i++ {
		count[int(s[i])-97]++
	}
	if len(s)%k != 0 {
		ps("-1")
		return
	}
	s = ""
	for i := 0; i <= 25; i++ {
		c := count[i] / k
		if count[i]%k == 0 {
			for j := 0; j < c; j++ {
				s = s + string(i+97)
			}
		} else {
			ps("-1")
			return
		}
	}
	for k > 0 {
		ps(s)
		k--
	}
}


package main
import (
	"fmt"
	"unicode/utf8"
)

func main() {
	var k int
	flag:=false
	var x string
	n:=make([]int,27)
	fmt.Scan(&k,&x)
	len:= utf8.RuneCountInString(x)
	for i:=0; i<len;i++ {
		n[int(x[i]-'a'+1)]++
	}
	for i:=1; i<=26;i++ {
			if n[i]%k!=0{
				fmt.Println("-1")
				flag=true
				break
			}
	}
	if flag==false {
		for q:=1;q<=k;q++ {
			for i:=1;i<=26;i++ {
				for j:=1;j<=n[i]/k;j++ {
					fmt.Print(string(i+'a'-1))
				}
			}
		}
	}
	fmt.Println()
}


package main

import (
	"fmt"
	"strings"
)

func kstring(str string, k int, table []int) {
	res := ""
	for i := 0; i < len(str); i++ {
		table[str[i]-97]++
	}
	for i := 0; i < 26; i++ {
		if table[i] != 0 {
			if table[i]%k == 0 {
				res += strings.Repeat(string(i+97), table[i]/k)
			} else {
				fmt.Println(-1)
				return
			}
		}
	}
	fmt.Println(strings.Repeat(res, k))
}

func main() {
	var k int
	var str string
	table := make([]int, 26)
	fmt.Scanln(&k)
	fmt.Scanln(&str)
	kstring(str, k, table)
}


package main

import (
	"fmt"
	"strings"
)

func kstring(str string, k int, table []byte) {
	res := ""
	for i := 0; i < len(str); i++ {
		table[str[i]-97]++
	}
	for i := 0; i < 26; i++ {
		if table[i] != 0 {
			if int(table[i])%k == 0 {
				res += strings.Repeat(string(i+97), int(table[i])/k)
			} else {
				fmt.Println(-1)
				return
			}
		}
	}
	fmt.Println(strings.Repeat(res, k))
}

func main() {
	var k int
	var str string
	table := make([]byte, 26)
	fmt.Scanln(&k)
	fmt.Scanln(&str)
	kstring(str, k, table)
}