n = int(input())
l = []

for _ in range(n):
	l.append(input())

answer = []
s = set()

for i in range(n - 1, 0, -1):
	print(l[i])
	if l[i] not in s:
	  s.add(l[i])
	  answer.append(l[i])

for _ in answer:
  print(_)


n = int(input())
l = []

for _ in range(n):
	l.append(input())

answer = []
s = set()

for i in range(n - 1, -1, -1):
	if l[i] not in s:
	  s.add(l[i])
	  answer.append(l[i])

for _ in answer:
  print(_)


import math

n = int(input())
names = []
for i in range(0,n):
	temp = []
	x = input()
	temp.append(x)
	temp.append(i)
	names.append(temp)

visited = []
for i in range(len(names)-1,-1,-1):
	if names[i][0] not in visited:
		print(names[i][0])
		visited.append(names[i][0])


import math

n = int(input())
names = {}
for i in range(0,n):
	x = input()
	names[x] = i
names = sorted(names.items(), key = lambda x: x[1])

ans = []
for key in names:
	ans.append(key[0])

for i in range(len(ans)-1,-1,-1):
	print(ans[i])


import math

n = int(input())
names = []
for i in range(0,n):
	temp = []
	x = input()
	temp.append(x)
	temp.append(i)
	names.append(temp)

visited = []
for i in range(len(names)-1,-1,-1):
	if names[i][0] in visited:
		continue
	else:
		print(names[i][0])
		visited.append(names[i][0])


n = int(input())
a = []
for i in range(n):
	s = input()
	if a.count(s) != 0:
		a.remove(s)
	a.append(s)
for i in range(len(a) - 1, -1, -1):
	print(a[i])


n = int(input())
a = []
b = {}
c = {}
for i in range(n):
	a.append(input())
a.reverse()
b = {}
for i in a:
	b[i] = 0
for i in range(n):
	if b[a[i]] == 0:
		print(a[i])
		b[a[i]] = 1


n = int(input())
a = []
b = {}
c = {}
for i in range(n):
	a.append(input())
cnt = 1
for i in a:
	c[i] = cnt
	cnt += 1
while True:
	for key, val in c.items():
		if val == max([i for i in c.values()]) and val != -1:
			print(key)
			c[key] = -1
	if max([i for i in c.values()]) == -1:
		exit()


n = int(input())
messages = [input() for x in range(n)]
users = {x: 0 for x in messages}
counter = 0
for x in messages:
    users[x] = counter
    counter += 1
for x in sorted(users.items(), key=lambda x: x[1], reverse=True):
    print(x[0])


n = int(input())
chats = []

for i in range(n):
    line = input()
    if line in chats:
        index = chats.index(line)
        del chats[index]
        chats.insert(0, line)
    else:
        chats.insert(0, line)

for x in chats:
    print(x)


from bisect import bisect_left
def mp():  return map(int,input().split())
def lt():  return list(map(int,input().split()))
def pt(x):  print(x)
def ip():  return input()
def it():  return int(input())
def sl(x):  return [t for t in x]
def spl(x): return x.split()
def aj(liste, item): liste.append(item)
def bin(x):  return "{0:b}".format(x)

n = it()
chatlist = []
deja = []
for i in range(n):
    s = ip()
    if deja == [] or bisect_left(deja,s) == len(deja) or deja[bisect_left(deja,s)] != s:
        if deja == []:
            deja.append(s)
        else:
            deja.insert(bisect_left(deja,s),s)
        chatlist.insert(0,s)
    else:
        chatlist.remove(s)
        chatlist.insert(0,s)
for item in chatlist:
    print(item)


def mp():  return map(int,input().split())
def lt():  return list(map(int,input().split()))
def pt(x):  print(x)
def ip():  return input()
def it():  return int(input())
def sl(x):  return [t for t in x]
def spl(x): return x.split()
def aj(liste, item): liste.append(item)
def bin(x):  return "{0:b}".format(x)

n = it()
dict = {}
L = [ip() for _ in range(n)][::-1]
for x in L:
    if not (x in dict):
        dict[x] = 1
        print(x)


n=int(input())

d={}

for x in [input() for i in range(n)][::-1]:

  if not (x in d): d[x]=1; print(x)

# Made By Mostafa_Khaled


# -*- coding: utf-8 -*-
"""
Created on Mon May 16 22:18:07 2016

@author: Alex
"""
l = list()
n = int(input())
for i in range(n):
    a = str(input())
    if a in l:
        l.remove(a)
    l.append(a)
i = len(l)
while(i>0):
    print(l[i-1])
    i -= 1


# -*- coding: utf-8 -*-
"""
Created on Mon May 16 22:18:07 2016

@author: Alex
"""
l = list()
s = set()
n = int(input())
for i in range(n):
    l.append(input())
for i in range(n):
    c = l[n-i-1]
    if c not in s:
        print(c)
        s.add(c)


n = int(input())
chats = [input() for s in range(n)]
unique = set()
chats = chats.reverse()
for elem in chats:
    if elem not in unique:
        unique.add(elem)
        print(elem)


n = int(input())
chats = [input() for s in range(n)]
i = 0
while i < len(chats):
    name = chats[i]
    while chats.count(name) > 1:
        chats.remove(name)
    i += 1
chats.reverse()
for elem in chats:
    print(elem, end='\n')


n = int(input())
chats = [input() for s in range(n)]
unique = set()
chats = reversed(chats)
for elem in chats:
    if elem not in unique:
        unique.add(elem)
        print(elem)


import sys
order=[]
appear={}
n=int(input())
for i in range(n):
    str_=input()
    name=''.join(c for c in str_ if c.isalpha())
    order.append(name)
for i in range (n):
    if order[n-1-i] not in appear:
        appear[order[n-1-i]]=1
        print(order[n-1-i])


import sys
order={}
n=int(input())
for i in range(n):
    str_=input()
    name=''.join(c for c in str_ if c.isalpha())
    if name:
        order[name]=i
i=n-1
while i>=0:
    for (a,b) in order.items():
        if b==i:
            print(a)
            order.pop(a)
            break
    i=i-1


import sys
order={}
n=int(input())
for i in range(n):
    str_=input()
    name=''.join(c for c in str_ if c.isalpha())
    if name:
        order[name]=i
i=n-1
while i>=0:
    for (a,b) in order.items():
        if b==i:
            print(a)
            break
    i=i-1


n = int(input())
l = []
for _ in range(n):
    l.append(input())
t = set()
for i in range(len(l)-1,-1,-1):
    if l[i] not in t:
        print(l[i])
        t.add(l[i])


n = int(input())
l = []
for _ in range(n):
    l.append(input())
t = set()
r = []
for i in range(len(l)-1,-1,-1):
    if l[i] not in t:
        r.append(l[i])
        t.add(l[i])
print('\n'.join(r))


from  sys import stdin,stdout
n=int(stdin.readline())
d=dict()
s=""
z=[stdin.readline() for _ in " "*n][::-1]
for i in z:
    if d.get(i,0)==0:d[i]=1;s+=i
stdout.write(s)


__author__ = 'Alexandret'

chats_amount = int(input())
chats_order = list()
for i in range(chats_amount):
    uid = input()
    if uid in chats_order:
        chats_order.remove(uid)
    chats_order.insert(0, uid)
print('\n'.join(chats_order))


__author__ = 'Alexandret'

chats_amount = int(input())
chats_last_message = dict()
for i in range(chats_amount):
    uid = input()
    chats_last_message[uid] = i

l = lambda x: x[1]
tmp = sorted(chats_last_message.items(), key=l, reverse=True)
for i in tmp:
    print(i[0])


stack=[]
s=set()
l=[]
for _ in range(int(input())):
    stack.append(input())
while len(stack)!=0:
    x=stack.pop()
    if x not in s:
        s.add(x)
        l.append(x)
for i in l:
    print(i)


import bisect
from collections import deque
n = int(input())
dq = deque()
for i in range(n):
    s=input()
    if s in dq:
        dq.remove(s)
        dq.appendleft(s)
    else:
        dq.appendleft(s)
for i in dq:
    print(i)


n=int(input())
s=set();a=[]
for x in [input() for i in range(n)][::-1]:
  if not (x in s): a+=[x]; s|={x}
print('\n'.join(a))


n=int(input())
rank={}
for i in range(n):
    rank[input()]=i

print('\n'.join(sorted(rank,key=lambda x:rank[x],reverse=True)))


n = int(input())
friends = [[]]*n
for i in range(n):
    friends[i]=input()

rank=[]
i=n-1

while i >=0:

    if friends[i] not in rank:

        rank.append(friends[i])

        i-=1

    else:

        i-=1

for i in range(len(rank)):
    print(rank[i])


import sys
import collections

_ = sys.stdin.readline()  # read count, not needed for us

names = collections.OrderedDict()

while True:
    name = sys.stdin.readline()
    name = name.strip()

    if not name:
        break

    if name not in names:
        names[name] = None

    names.move_to_end(name)

sys.stdout.write('\n'.join(reversed(names)))


import sys
import operator

_ = sys.stdin.readline()  # read count, not needed for us

name2activity = {}

for name in iter(sys.stdin.readline, ''):
    name = name.strip()

    name2activity[name] = 0

    for k, v in name2activity.items():
        name2activity[k] = v + 1

sys.stdout.write(('\n'.join(
    x[0] for x in
    sorted(name2activity.items(), key=operator.itemgetter(1))
)))


n=int(input())
l=[]
for i in range(n):
    l.append(input())

#print(l)
p=len(l)
for i in range(p):
    p=len(l)
    #print(p)
    if p>0:
        k=l.pop()
    while k in l:
        l.pop(l.index(k))

    if p>0:
        print(k)


n=int(input())
l=[]
for i in range(n):
    f=input()
    if f in l:
        #print(l.pop(l.index(f)))
        l.pop(l.index(f))
        l.append(f)
        #print(l)
    else:
        l.append(f)

#print(l)
for i in range(len(l)):
    #print("I'm in while")
    print(l.pop())


class Nodes:
    def __init__(self,name):
        self.name=name
        self.next=None
        self.prev=None

n=int(input())
d={}
curr=None

for i in range(n):
    chat=input()
    if chat in d:
        curr.next=d[chat]

        if d[chat].prev is not None:
            d[chat].prev.next=d[chat].next

        if d[chat].next is not None:
            d[chat].next.prev=d[chat].prev

        d[chat].prev=curr
        curr.next=d[chat]
        curr=d[chat]

    else:
        d.update({chat:Nodes(chat)})
        d[chat].prev=curr
        if (i!=0):
            curr.next=d[chat]

        curr=d[chat]

while curr is not None:
    print(curr.name)
    curr=curr.prev


n=int(input())
l=[]
for i in range(n):
    f=input()
    if f in l:
        #print(l.pop(l.index(f)))
        l.pop(l.index(f))
        l.append(f)
        #print(l)
    else:
        l.append(f)

#print(l)
for i in range(len(l)):
    #print("I'm in while")
    print(l[len(l)]-i)


import sys

n=int(input())
a=[input() for i in range(n)]

mp={}

for i in range(n-1,-1,-1):

    try:
        mp[a[i]]+=1
    except:
        print(a[i])
        mp[a[i]]=1


n=int(input())
l=[]
for i in range(n):
    f=input()
    if f in l:
        #print(l.pop(l.index(f)))
        l.pop(l.index(f))
        l.append(f)
        #print(l)
    else:
        l.append(f)

print(l)
for i in range(len(l)):
    #print("I'm in while")
    print(l.pop())


n=int(input())
l=[]
for i in range(n):
    f=input()
    if f in l:
        #print(l.pop(l.index(f)))
        l.pop(l.index(f))
        l.append(f)
        #print(l)
    else:
        l.append(f)

#print(l)
k=len(l)-1
for i in range(len(l)):
    #print("I'm in while")

    print(l[k])
    k-=1


#from datetime import datetime
#startTime = datetime.now()
class Nodes:
    def __init__(self,name):
        self.name=name
        self.next=None
        self.prev=None

n=int(input())
d={}
curr=None

for i in range(n):
    chat=input()
    if chat in d:
        curr.next=d[chat]

        if d[chat].prev is not None:
            d[chat].prev.next=d[chat].next

        if d[chat].next is not None:
            d[chat].next.prev=d[chat].prev

        d[chat].prev=curr
        curr.next=d[chat]
        curr=d[chat]

    else:
        d.update({chat:Nodes(chat)})
        d[chat].prev=curr
        if (i!=0):
            curr.next=d[chat]

        curr=d[chat]

while curr is not None:
    print(curr.name)
    curr=curr.prev

#print(datetime.now() - startTime)


I , d = input, {}
for i in [I() for i in range(int(I()))][::-1]:
    if i not in d : print(i)
    d[i] = 1


a, d = [input() for i in range(int(input()))], {}
for i in reversed(a):
    if i not in d.keys() : print(i)
    d[i] = 1


n = int(input())
inp = []
a = []
for i in range(0, n):
    b = input()
    inp.append(b)
inp = inp[::-1]
for i in inp:
    if i not in a :
        a.append(i)
for i in a:
    print(i)


n = int(input())
inp = []
a = []
s = set()
for i in range(0, n):
    b = input()
    inp.append(b)
inp = inp[::-1]
for i in inp:
    if i not in s :
        a.append(i)
        s |= set([i])
for i in a:
    print(i)


import sys

Lines = []
for Line in sys.stdin:
  Lines.append(Line.rstrip('\n'))

# Lines=["4",
# "alex",
# "ivan",
# "roman",
# "ivan"]

# Lines=["8",
# "alina",
# "maria",
# "ekaterina",
# "darya",
# "darya",
# "ekaterina",
# "maria",
# "alina"]

n = int(Lines[0])
del(Lines[0])
f=[]
for i in range(n):
   for j in f:
      if j==Lines[i]:
        f.remove(Lines[i])
   f.insert(0,Lines[i])
for i in range(len(f)):
  print(f[i])


import sys
from collections import OrderedDict

Lines = []
for Line in sys.stdin:
  Lines.append(Line.rstrip('\n'))

# Lines=["4",
# "alex",
# "ivan",
# "roman",
# "ivan"]

# Lines=["8",
# "alina",
# "maria",
# "ekaterina",
# "darya",
# "darya",
# "ekaterina",
# "maria",
# "alina"]

n = int(Lines[0])
del(Lines[0])
#f=[]

# print(Lines)
p = list(OrderedDict.fromkeys(Lines[::-1]))

# for i in range(n):
#    for j in f:
#       if j==Lines[i]:
#         f.remove(Lines[i])
#    f.insert(0,Lines[i])
for i in range(len(p)):
  print(p[i])


n = int(input())
recipients = [input() for _ in range(0, n)]

alreadydone = set()

for i in range(0, n):
	c = recipients[n - i - 1]
	if c not in alreadydone:
		print(c)
		alreadydone.add(c)


n = int(input())
recipients = [input() for _ in range(0,n)]
done = set()
for i in range(0,n):
  c = recipients[n - i - 1]
  if c not in done:
    print(c)
	done.add(c)


n = int(input())
data = [input() for i in range(n)]
res = []
for v in reversed(data):
  if not v in res:
    print(v)
    res.append(v)


n = int(input())
data = [input() for i in range(n)]
res = set()
for v in reversed(data):
  if not v in res:
    print(v)
    res.add(v)


uniq = {}
n = int(input())
s = [0]*n
for i in range(n):
    s[i] = input()
for i in s[::-1]:
    if i not in uniq:
        print(i)
        uniq[i] = 1


n = int(input())
s = [0]*n
for i in range(n):
    s[i] = input()
ss = []
for i in s[::-1]:
    if i not in ss:
        ss.append(i)
for i in ss:
    print(i)


n = int(input())
s = [0]*n
for i in range(n):
    s[i] = input()
ss = []
for i in s[::1]:
    if i not in ss:
        ss.append(i)
for i in ss:
    print(i)


n = int(input())
s = [0]*n
for i in range(n):
    s[i] = input()
ss = []
for i in s:
    if i not in ss:
        ss.append(i)
    else:
        ss.remove(i)
        ss.append(i)
for i in ss[::-1]:
    print(i)


n=int(input())
l=[input() for i in range(n)]]
m=set()
for i in range(n-1,-1,-1):
    if l[i] not in m:
        print(l[i])
        m.add(l[i])


n=int(input())
l=[input() for i in range(n)]
m=[]
for i in range(n-1,-1,-1):
    if l[i] not in m:
        m.append(l[i])
for i in m:
    print(i)


n=int(input())
l=[input() for i in range(n)]
m=set()
for i in range(n-1,-1,-1):
    if l[i] not in m:
        print(l[i])
        m.add(l[i])


from sys import stdin
input()
d = {s: i for i, s in enumerate(stdin.read().splitlines())}
print('\n'.join(sorted(d.keys(), key=d.get, reverse=True)))


def main():
    d = {input(): i for i in range(int(input()))}
    print('\n'.join(sorted(d.keys(), key=d.get, reverse=True)))

if __name__ == '__main__':
    main()


d={}
for i in range(int(input())):
    s=input()
    d[s]=i
d=sorted(d.items(),key=lambda x:x[1],reverse=True)
for i in d:
    print(i[0])


l=[]
for i in range(int(input())):
    s=input()
    if s in l:
        l.remove(s)
    l.insert(0,s)
for i in l:
    print(i)


n = int(input())
chat = {}
for i in range(n):
    chat[input()] = i
c = {}
for i in chat.keys():
    c[chat[i]] = i
m = []
for i in sorted(list(c.keys()), reverse = True):
    m.append(c[i])
print(*m, sep = '\n')


n = int(input())
chat = {}
for i in range(n):
    chat[input()] = i
c = {}
for i in chat.keys():
    c[chat[i]] = i
t = list(c.keys())
t.sort(reverse = True)
m = []
for i in t:
    m.append(c[i])
print(*m, sep = '\n')


n = int(input())
chat = {}
for i in range(n):
    t = input()
    chat[t] = (i,t)
for tup in sorted(chat.values(),reverse = True):
    print(tup[1])


chat = [input() for i in range(int(input()))]
l = {}
while chat:
    t = chat.pop()
    if t not in l:
        l[t] = 0
        print(t)


chat = [input() for i in range(int(input()))]
l = []
while chat:
    t = chat.pop()
    if t not in l:
        l.append(t)
        print(t)


n = int(input())
chat = {}
for i in range(n):
    chat[input()] = i
c = {}
for i in chat.keys():
    c[chat[i]] = i
t = list(c.keys())
t.sort(reverse = True)
for i in t:
    print(c[i])


n = int(input())
chat = {}
for i in range(n):
    t = input()
    chat[t] = (-i,t)
for tup in sorted(chat.values()):
    print(tup[1])


n = int(input())
displayed = {}
top = None
for i in range(n):
    chat = input()
    try:
        a = displayed[chat]
        previous = a[0]
        nextone = a[1]
        if previous:
            displayed[previous][1] = nextone
            if nextone: displayed[nextone][0]=previous
            displayed[chat] = [None, top]
            if top:
                displayed[top][0] = chat
            top = chat
    except KeyError:
        displayed[chat] = [None, top]
        if top:
            displayed[top][0] = chat
        top = chat
    print(displayed)
    print(top)
li = []
while top:
    #print(top)
    li.append(top)
    top = displayed.pop(top)[1]
    #print(displayed)

print('\n'.join(li))


n = int(input())
displayed = {}
top = None
for i in range(n):
    chat = input()
    try:
        a = displayed[chat]
        previous = a[0]
        nextone = a[1]
        if previous:
            displayed[previous][1] = nextone
            if nextone: displayed[nextone][0]=previous
            displayed[chat] = [None, top]
            top = chat
    except KeyError:
        displayed[chat] = [None, top]
        if top:
            displayed[top][0] = chat
        top = chat
    #print(displayed)
li = []
while top:
    #print(top)
    li.append(top)
    top = displayed.pop(top)[1]
    #print(displayed)

print('\n'.join(li))


n = int(input())
displayed = {}
top = None
for i in range(n):
    chat = input()
    try:
        a = displayed[chat]
        previous = a[0]
        nextone = a[1]
        if previous:
            displayed[previous][1] = nextone
            if nextone: displayed[nextone][0]=previous
            displayed[chat] = [None, top]
            if top:
                displayed[top][0] = chat
            top = chat
    except KeyError:
        displayed[chat] = [None, top]
        if top:
            displayed[top][0] = chat
        top = chat
    #print(displayed)
    #print(top)
li = []
while top:
    #print(top)
    li.append(top)
    top = displayed.pop(top)[1]
    #print(displayed)

print('\n'.join(li))


n, d = int(input()), {}
for x in [input() for i in range(n)][::-1]:
	if x not in d:
		d[x] = 1
		print(x)


n = int(input())
A = []
B = set()

for i in range(n):
    s  = input()
    A.append(s)
    B.add(s)

i = n

while i>0:
    p = A.pop()
    if p in B:
        B.remove(p)
        print(p)
    i = i-1


from sys import stdin
s = set()
n = int(stdin.readline())
a = stdin.readlines()
a.reverse()
for i in a:
 j = i.strip()
 if j not in s:
  print j
  s.add(j)


n = int(input())
ST = []
SET = set()

for i in range(n):
    s  = input()
    ST.append(s)
    SET.add(s)

i = n

while i>0:
    p = ST.pop()
    if p in SET:
        SET.remove(p)
        print(p)
    i = i-1


num = input()
arr = []

for i in range(int(num)):
  strr = input()
  if (strr in arr):
    arr.remove(strr)
  arr.append(strr)

while len(arr):
  print(arr.pop())


num = input()
printed = set()
names = []

for i in range(int(num)):
  names.append(input())

for i in reversed(names):
  if i not in printed:
    print(i)
    printed.add(i)


num = input()
printed = {}
names = []

for i in range(int(num)):
  names.append(input())

for name in reversed(names):
  if name not in printed: # O(1)
    print(name)
    printed[name] = True


n=int(input())
l=[]
while n:
    l.append(input())
    n-=1
a=set()
for i in reversed(l):
    if not i in a:
        a.add(i)
        print(i)


#!/usr/bin/python3

n = int(input())

friend_list = dict()

for i in range(n):
    friend_list[input()] = i

friends = list(friend_list.keys())
friends.sort(reverse=True, key = lambda x: friend_list[x])

for friend in friends:
    print(friend)


#!/usr/bin/python3

n = int(input())

friend_list = []

for i in range(n):
    friend_list.append(input())

ans = []

for friend in friend_list[::-1]:
    if friend not in ans:
        ans.append(friend)

for friend in ans:
     print(friend)


#!/usr/bin/python3

n = int(input())

friend_list = []

for i in range(n):
    friend = input()
    if friend not in friend_list:
        friend_list.append(friend)

for friend in friend_list:
     print(friend)


require 'set'
n = gets.to_i
chats = []
n.times do
    chats.push(gets.chomp)
end
s = Set.new
chats.reverse.each do |name|
    if !s.include?(name)
        puts name
        s << name
    end
end


#include<iostream>
using namespace std;
int n,i,j,a[1000],m,temp,temp1;
int main()
{
    long int min = 1000000;
    cin >> n;
    for (i = 0; i < n;i++)
    {
        cin >> a[i];
    }
    for (i = 0; i < n; i++)
    {
        temp = 0;
        for (j = 0; j < a[i]; j++)
        {
            temp1 = 0;
            cin >> m;
            temp1 = (5 * m + 15);
            temp = temp1 + temp;
        }
        if (temp < min)
            min = temp;
    }
    cout << min;
}


#include<iostream>
using namespace std;
int n, i, j, k,m, min, temp,temp1;
int main()
{
    min = 100000;

    cin >> n;
    for (i = 0; i<n; i++)
    {
        temp = 0;
        cin >> k;
        for (j = 0; j<k; j++)
        {

            temp1 = 0;
            cin >> m;
            temp1 = (m * 5+15) ;
            temp = temp1 + temp;
        }

        if (temp<min)
            min = temp;
    }
    cout << min;
    return 0;
}


#include<iostream>
using namespace std;
int n,i,j,k,m,temp,temp1;
int main()
{
    int min =10000;

    cin >> n;
    for (i = 0; i<n; i++)
    {
        temp = 0;
        cin >> k;
        for (j = 0; j<k; j++)
        {

            temp1 = 0;
            cin >> m;
            temp1 = (m * 5+15) ;
            temp = temp1 + temp;
        }

        if (temp<min)
            min = temp;
    }
    cout << min;
    return 0;
}


#include<iostream>
using namespace std;
int n,i,j,k,m,min,temp,temp1;
int main()
{
    min = 10000;

    cin >> n;
    for (i = 0; i<n; i++)
    {
        temp = 0;
        cin >> k;
        for (j = 0; j<k; j++)
        {

            temp1 = 0;
            cin >> m;
            temp1 = (m * 5+15) ;
            temp = temp1 + temp;
        }

        if (temp<min)
            min = temp;
    }
    cout << min;
    return 0;
}


#include<iostream>
using namespace std;
int n,i,j,a[100],m,temp,temp1;
int main()
{
    int min = 10000;
    cin >> n;
    for (i = 0; i < n;i++)
    {
        cin >> a[i];
    }
    for (i = 0; i < n; i++)
    {
        temp = 0;
        for (j = 0; j < a[i]; j++)
        {
            temp1 = 0;
            cin >> m;
            temp1 = (5 * m + 15);
            temp = temp1 + temp;
        }
        if (temp < min)
            min = temp;
    }
    cout << min;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <sstream>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <cmath>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;

#define mp make_pair

int main()
{
#ifdef KOCH
	freopen("abc.txt", "r", stdin);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int64 n;
	cin >> n;
	vector<int64> v(n);
	int64 res = 1e15;
	for (int i = 0; i < n; ++i) cin >> v[i];
	for (int i = 0; i < n; ++i)
	{
		int64 sum = 0;
		sum += v[i] * 15ll;
		for (int j = 0; j < v[i]; ++j)
		{
			int64 a;
			cin >> a;
			sum += a * 5;
		}
		res = min(res, sum);
	}
	cout << res << endl;
	return 0;

}


#include<iostream>
#include<vector>
using namespace std;

int main(){

	int n, adamiani[100];
	int sumtemp = 0;
	int temp;
	vector<int> dro;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> adamiani[i];
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < adamiani[i]; j++)
		{
			cin >> temp;
			sumtemp += temp;
		}
		dro.push_back(adamiani[i]*15+5*sumtemp);
		sumtemp = 0;
	}
	int min = dro[0];

	for (int i = 0; i < dro.size(); i++)
	{
		if (min > dro[i])
			min = dro[i];
	}
	/*cout << endl;
	for each (int i in dro)
	{
		cout << i << endl;
	}*/

	cout << min;

	return 0;
}


#include<iostream>
#include<vector>
using namespace std;

int main(){

	int n, adamiani[100];
	int sumtemp = 0;
	int temp;
	vector<int> dro;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> adamiani[i];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < adamiani[i]; j++)
		{
			cin >> temp;
			sumtemp += temp;
		}
		dro.push_back(adamiani[i]*15+5*sumtemp);
		sumtemp = 0;
	}
	int min = dro[0];

	for (int i = 1; i < dro.size(); i++)
	{
		if (min < dro[i])
			min = dro[i];
	}
	cout << min;

	return 0;
}


#include <iostream>

using namespace std;

int main()
{
          int n = 0, l = 0, sum = 0, lim = 1000000000;
          cin >> n;
          int *m = new int [n];
          for (int i = 0; i < n; i++)
          {
                    cin >> m[i];
          }
          for (int i = 0; i < n; i++)
          {
                    for (int j = 0; j < m[i]; j++)
                    {
                              cin >> l;
                              sum += l * 5 + 15;
                    }
                    if (sum < lim)
                    {
                              lim = sum;
                    }
                    sum = 0;
          }
          cout << lim;
}


#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int cash,people,items,counter=0;
	cin>>cash;
	vector<int>it;
	vector<int>p;
	vector<int>t;

	for(int i=0;i<cash;i++)
	{
		int np;
		cin>>np; p.push_back(np);
	}

	for(int i=0;i<cash;i++)
	{
		int checker=0;
		while(checker!=p[i])
		{int f; cin>>f; it.push_back(f);checker++;}
	}

	for(int i=0;i<cash;i++)
	{
		int checker=0,time=0;
		while(checker!=p[i])
		{time=time+it[counter]*5;checker++;counter++;}
		time=time+p[i]*15;t.push_back(time);
	}

	int min=t[0];
	for(int i=1;i<t.size();i++)
	{
		if(t[i]<min)
			min=t[i];
	}
	cout<<min<<endl;
	return 0;
}


//Program by WhiteDevil
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

long long ans[101], t;
int main()
{
    int n, k[101];
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> k[i];
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= k[i]; j++){
            cin >> t;
            ans[i] += t * 5;
        }
        ans[i] += 15;
    }
    ans[0] = ans[1];
    for (int i = 1; i <= n; i++){
        if (ans[0] > ans[i])
            ans[0] = ans[i];
    }

    cout << ans[0];
    return 0;
}


//Program by WhiteDevil
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

long long ans[101], t;
int main()
{
    int n, k[101];
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> k[i];
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= k[i]; j++){
            cin >> t;
            ans[i] += t * 5;
        }
        ans[i] += k[i]*15;
    }
    ans[0] = ans[1];
    for (int i = 1; i <= n; i++){
        if (ans[0] > ans[i])
            ans[0] = ans[i];
    }

    cout << ans[0];
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

struct t{
	int p, i;
};
void main(){
	int n ,x;
	cin >> n;
	t *a = new t[n];
	for (int i = 0; i < n; i++){
		cin >> a[i].p;
		a[i].i = 0;
	}

	for (int j = 0, i = 0; i < n&& j < a[i].p;  j++){
			cin >>x ;
			a[i].i += x;
			if (j + 1 == a[i].p){
				i++;
				j = -1;
			}
		}

	for (int i = 0; i < n; i++){
		a[i].p = a[i].p * 15 + 5 * a[i].i;
	}
	int min = a[0].p;
	for (int i = 0; i < n; i++){
		if (min >a[i].p){
			min = a[i].p;
		}
	}
	cout << min;
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <set>
#include <deque>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <sstream>
#include <bitset>
#include <deque>
//#include <WinSock2.h>

using namespace std;

int main(){
    vector<int> arr;
    vector<int> rez;
    int n;
    cin >> n;
    arr.resize(n);
    rez.resize(n);
    for(int i = 0; i < n; i++){
        int q;
        cin >> q;
        arr[i] = q;
    }
    int q = 0;
    int cur = 0;
    for(int i = 0; i < arr.size(); i++){
        for(int j = 0; j < arr[i]; j++){
            q = 0;
            cur = 0;
            cin >> q;
            cur+=5*q;
            cur+=15;
            rez[i] += cur;
        }
    }
    sort(rez.begin(),rez.end());
    cout << rez[0];
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;
int a[1010][1010];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i][0];
    for(int i=0;i<n;i++)
    for(int j=1;j<=a[i][0];j++)
        cin>>a[i][j];
    int min0;
    for(int i=0;i<n;i++)
    {
        int s=15*a[i][0];
        for(int j=1;j<=a[i][0];j++)
            s+=a[i][j]*5;
        if(i==0)min0=s;
        else if(min0>s)min0=s;
        //cout<<s<<endl;
    }cout<<min0<<endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(){
	int chel, min = 32787;
	cin >> chel;
	int *que = new int [chel + 1];
	int **qq = new int *[chel + 1];
	int *sum = new int [chel + 1];

	for (int i = 0; i < chel; i++){
		cin >> que[i];
		qq[i] = new int [que[i] + 1];
		sum[i] = 0;
	}

	for (int i = 0; i < chel; i++){
		for (int j = 0; j < que[i]; j++){
			cin >> qq[i][j];
		}
	}

	for (int i = 0; i < chel; i++){
		for (int j = 0; j < que[i]; j++){
			sum[i] += (qq[i][j] * 5);
		}
		sum[i] += que[i] * 15;
	}

	for (int i = 0; i < chel; i++){
		if (sum[i] < min){
			min = sum[i];
		}
	}
	cout << min;
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(){
	int chel, min = 10000000;
	cin >> chel;
	int *que = new int [chel + 1];
	int **qq = new int *[chel + 1];
	int *sum = new int [chel + 1];

	for (int i = 0; i < chel; i++){
		cin >> que[i];
		qq[i] = new int [que[i] + 1];
		sum[i] = 0;
	}

	for (int i = 0; i < chel; i++){
		for (int j = 0; j < que[i]; j++){
			cin >> qq[i][j];
		}
	}

	for (int i = 0; i < chel; i++){
		for (int j = 0; j < que[i]; j++){
			sum[i] += (qq[i][j] * 5);
		}
		sum[i] += que[i] * 15;
	}

	for (int i = 0; i < chel; i++){
		if (sum[i] < min){
			min = sum[i];
		}
	}
	cout << min;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{

	int y;
	cin>>y;
	int *sum=new int[y];
	int *p=new int[y];
	for(int i=0;i<y;i++)
	{
		cin>>p[i];

	}
	  for(int i=0;i<y;i++)
	{
		sum[i]=0;
	}
	int **x=new int *[y];
	for(int i=0;i<y;i++)
	{

		x[i]=new int [p[i]];
		for(int j=0;j<p[i];j++)
		{
			cin>>x[i][j];
			sum[i]+=(5*x[i][j]);
		}
		sum[i]+=15*p[i];
	}
	int min=sum[0];
	for(int i=1; i<y;i++)
		if(sum[i]<=min)
	min=sum[i];
	cout<<min;

	return 0;
}


#include<stdio.h>
#include<stdlib.h>

#define time_cash  15
#define time_item 5
int main(){
    int no_cashier, line_cashier[10000],item;
    int min = 1000000;
    int time = 0;
    int k=0, j = 0;
    scanf("%d",&no_cashier);

        for(int i=0;i<no_cashier;i++){
            scanf("%d",&line_cashier[i]);
        }
        while(k<no_cashier){
            time =0;
        for( j=0;j<line_cashier[k];j++){
            scanf("%d",&item);
            time = time + item * time_item;

        }

        //--j;
        time = time + j*15;
            //printf(" time is :%d\n",time);
            if(min > time)
                min = time;
    k++;
    }
no_cashier--;

    printf("%d\n",min);
return 0;
}

/*
4
1 4 3 2
100
1 2 2 3
1 9 1
7 8*/


#include<stdio.h>
#include<stdlib.h>

#define time_cash  15
#define time_item 5
int main(){
    int no_cashier, line_cashier[10000],item;
    int min = 10000;
    int time = 0;
    int k=1, j = 1;
    scanf("%d",&no_cashier);

        for(int i=1;i<=no_cashier;i++){
            scanf("%d",&line_cashier[i]);
        }
        while(k<=no_cashier){
            time =0;
        for( j=1;j<=line_cashier[k];j++){
            scanf("%d",&item);
            time = time + item * time_item;

        }

        --j;
        time = time + j*15;
            //printf(" time is :%d\n",time);
            if(min > time)
                min = time;
    k++;
    }
no_cashier--;

    printf("%d\n",min);
return 0;
}

/*
4
1 4 3 2
100
1 2 2 3
1 9 1
7 8*/


//In the name of God:)
#include <iostream>
using namespace std;
int n, K[100], M[100][100], S[100], minmin;
int main()
{
    minmin=1e9;
    cin>> n;
    for (int i=0; i<n; i++)
        cin>> K[i];
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<K[i]; j++)
            cin>> M[i][j];
    }
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<K[i]; j++)
            S[i]+=M[i][j];
        S[i]*=5;
        S[i]+=15*K[i];
    }
    for (int i=0; i<n; i++)
    {
        if (S[i]<minmin)
            minmin=S[i];
    }
    cout<< minmin;
    return 0;
}


#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
using namespace std;
int  main ()
{
int n,n1[100],n2[100],sum[100];
cin>>n;
for ( int i =0 ; i<100 ;i++)
	sum[i] =0;
for ( int i =0 ; i <n; i++)
	cin>>n1[i];
for ( int i = 0 ; i<n ;i++)
{
for ( int j = 0 ; j<n1[i] ;j++)
{
cin>>n2[j];
n2[j] *=5;
n2[j]+= 15;
sum[i]+=n2[j];
}

}

int x = sum [0] ;
for ( int i =0 ; i<n; i++)
{
	if ( sum [i] < x )
		x=sum[i];
}

cout<<x<<endl;
return 0 ;
}


#include<iostream>
#include<algorithm>
using namespace std;
void main(){int m;
int n;int sum=10000000;
cin>>n;int shit=0;
int k[100];
for(int i=0;i<n;i++){
cin>>k[i];

}for(int i=0;i<n;i++){
	for(int j=0;j<k[i];j++){
	cin>>m;
	shit+=(m*5+15);

	}

	sum=min(sum,shit);shit =0;}

cout<<sum<<endl;

}


#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int no_of_cashiers, min, x, comparison; min = 0; comparison = 0;
	cin >> no_of_cashiers;
	int* arr = new int[no_of_cashiers];
	for (int i = 0; i < no_of_cashiers; i++){
		cin >> arr[i];
	}
	for (int j = 0; j < no_of_cashiers; j++){
		for (int h = 0; h < arr[h]; h++){
			cin >> x;
			comparison += ((x * 5) + 15);
		}
		if (comparison < min){ min = comparison; }
	}
	cout << min;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int no_of_cashiers, min, x, comparison; min = 0; comparison = 0;
	cin >> no_of_cashiers;
	int* arr = new int[no_of_cashiers];
	for (int i = 0; i < no_of_cashiers; i++){
		cin >> arr[i];
	}

	for (int j = 0; j < no_of_cashiers; j++){
		for (int h = 0; h < arr[j]; h++){
			cin >> x;
			comparison += ((x * 5) + 15);
		}
		if (j == 0){ min = comparison; }
		else if (comparison < min){
			min = comparison;
		}
	}

	cout << min<<endl;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int no_of_cashiers, min, x, comparison; min = 0; comparison = 0;
	cin >> no_of_cashiers;
	int* arr = new int[no_of_cashiers];
	for (int i = 0; i < no_of_cashiers; i++){
		cin >> arr[i];
	}

	for (int j = 0; j < no_of_cashiers; j++){
		for (int h = 0; h < arr[j]; h++){
			cin >> x;
			comparison += ((x * 5) + 15);
		}
		if (j == 0){ min = comparison; }
		else if (comparison < min){
			min = comparison;
		}
		comparison = 0;
	}

	cout << min<<endl;
	return 0;
}


#include <cstdio>

const int maxn=100;

int main (){
	int n,i,j,k,min;
	int p[maxn+13],s[maxn+13]={0};
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&p[i]);
		s[i]=p[i]*15;
	}
	for (i=1;i<=n;i++)
		for (j=1;j<=p[i];j++)
		{
			scanf("%d",&k);
			s[i]=s[i]+k*5;
		}
	min=s[1];
	for (i=2;i<=n;i++)
		if (s[i]<min) min=s[i];
	printf("%d\n",min);
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
typedef vector<int>vi;
int main()
{
	int n,sum,m;
	cin>>n;
	vi vec1(n);
	for(int i=0;i<n;i++)
		cin>>vec1[i];
	vi vec2;
	for(int i=0;i<n;i++)
	{
		sum=0;
		for(int j=0;j<vec1[i];j++)
		{
			cin>>m;
			sum+=m*5;
		}
		sum+=15*vec1[i];
		vec2.push_back(sum);
	}
	sort(vec2.begin(),vec2.end());
	cout<<vec2[0]<<endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

#define sqr(a) (a)*(a)
#define mp make_pair

typedef long double dd;
typedef long long ll;
typedef pair<int, int> pa;
const dd PI=acos(-1.0);
const dd EPS=1e-12;
const int MAXN=(int)1e5;
const int INF=(int)2e9;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

#define sqr(a) (a)*(a)
#define mp make_pair

typedef long double dd;
typedef long long ll;
typedef pair<int, int> pa;
const dd PI=acos(-1.0);
const dd EPS=1e-12;
const int MAXN=(int)1e5;
const int INF=(int)2e9;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, a[100];
	scanf("%d", &n);
	for(int i=0; i<n; ++i)
		scanf("%d", &a[i]);

	int ans=INF;

	for(int i=0; i<n; ++i){

		int sum = 0;

		for(int j=0; j<a[i]; ++j){
			int num; scanf("%d", &num);
			sum += num*5 + 15;
		}

		ans = min(ans, sum);
	}

	printf("%d", ans);

	return 0;
}


#include<iostream>
using namespace std;
int main(){
int cash,num[100],person[100],sum=0,max=0,temp;
cin>>cash;
for(int i=0; i<cash;i++)
    cin>>num[i];

for(int i=0;i<cash;i++){
    sum=0;
    for(int j=0;j<num[i];j++){
    cin>>temp;
    sum+=temp;
    }

if((5*sum)+(num[i]*15)<max||max==0)
    max=(5*sum)+(num[i]*15);
}
cout<<max;

return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <memory.h>
#include <assert.h>
#include <complex>
#include <ctime>
#include <cstdlib>
using namespace std;

#pragma comment(linker, "/STACK:100000000")

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define ll long long
#define ull unsigned long long

int mas[100100];

int main() {
    //freopen("input.txt", "rt", stdin);
    int n;
    scanf("%d", &n);
    int res = 1000000000;
    for(int i = 0; i < n; i++) scanf("%d", &mas[i]);
    for(int i = 0; i < n; i++) {
        int val = 0;
        val += 15 * mas[i];
        for(int j = 0; j < mas[i]; j++) {
            int m;
            scanf("%d", &m);
            val += m * 5;
        }
        res = min(res, val);
    }
    printf("%d", res);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <memory.h>
#include <assert.h>
#include <complex>
#include <ctime>
#include <cstdlib>
using namespace std;

#pragma comment(linker, "/STACK:100000000")

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define ll long long
#define ull unsigned long long

int mas[100100];

int main() {
    //freopen("input.txt", "rt", stdin);
    int n;
    scanf("%d", &n);
    int res = 1000000000;
    for(int i = 0; i < n; i++) {
        int val = 0;
        int k;
        scanf("%d", &k);
        val += 15 * k;
        for(int j = 0; j < k; j++) {
            int m;
            scanf("%d", &m);
            val += m * 5;
        }
        res = min(res, val);
    }
    printf("%d", res);
    return 0;
}


#include <iostream>
#include <cmath>
#include<string>
using namespace std;
void main()
{
	int x,w,t,n;
	double arr[100],p[101],y;
	cin>>n;
	for(t=0;t<n;t++)
		cin>>arr[t];
	for(t=0;t<n;t++)
	{   w=0;
		for(x=0;x<arr[t];x++)
		{ cin>>y; w+=(y*5);}
		p[t]=w+(arr[t]*15);
	}y=100000000000000;
	for(t=0;t<n;t++)
	{if(p[t]<y) y=p[t];}
	cout<<y<<endl;

	}


#include <iostream>
using namespace std;
int main()
{
int n,ma=0,arr[100],i,s=0,it;
cin>>n;
for(i=0;i<n;i++)
cin>>arr[i];
for(i=0;i<n;i++)
{
for(int c=0;c<arr[i];c++)
{
cin>>it;
s+=it;
}
s*=5;
s+=15*arr[i];
if(i==0||s<ma)
ma=s;
s=0;
}
cout<<ma<<endl;
return 0;
}


#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
	int p = 0, k[100], ch = 0, m[100][100], min_hui = 500000, i, j;

	cin >> p; /*kol-vo kass*/
	for (i = 0; i < p; i++)
	{
		cin >> k[i]; /*kol-vo chelovek*/
	}
	for (i = 0; i < p; i++)
	{
		ch = 0;
		for (j = 0; j < k[i]; j++)
		{
			cin >> m[i][j];
			ch += m[i][j] * 5 + 15;
		}
		if (min_hui > ch)
		{
			min_hui = ch;
		}

		cout << min_hui << endl;
	}
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int p = 0, k[100], ch = 0, m[100][100], min_hui = 500000, i, j;

	cin >> p; /*kol-vo kass*/
	for (i = 0; i < p; i++)
	{
		cin >> k[i]; /*kol-vo chelovek*/
	}
	for (i = 0; i < p; i++)
	{
		ch = 0;
		for (j = 0; j < k[i]; j++)
		{
			cin >> m[i][j];
			ch += m[i][j] * 5 + 15;
		}
		if (min_hui > ch)
		{
			min_hui = ch;
		}
	}
	cout << min_hui << endl;
	return 0;
}


#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
	int p = 0, k[100], ch = 0, m[100][100], min_hui = 500000, i, j;

	cin >> p; /*kol-vo kass*/
	for (i = 0; i < p; i++)
	{
		cin >> k[i]; /*kol-vo chelovek*/
	}
	for (i = 0; i < p; i++)
	{
		ch = 0;
		for (j = 0; j < k[i]; j++)
		{
			cin >> m[i][j];
			ch += m[i][j] * 5 + 15;
		}
		if (min_hui > ch)
		{
			min_hui = ch;
		}

		cout << min_hui << endl;
	}
	system("PAUSE");
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int p = 0, k[100], ch = 0, m[100][100], min_hui = 500000, i, j;

	cin >> p; /*kol-vo kass*/
	for (i = 0; i < p; i++)
	{
		cin >> k[i]; /*kol-vo chelovek*/
	}
	for (i = 0; i < p; i++)
	{
		ch = 0;
		for (j = 0; j < k[i]; j++)
		{
			cin >> m[i][j];
			ch += m[i][j] * 5 + 15;
		}
		if (min_hui > ch)
		{
			min_hui = ch;
		}

		cout << min_hui << endl;
	}
	return 0;
}


#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main()
{
    int n, input;
    unsigned long long counter;
    vector<int> k;
    set<unsigned long long> data;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> input;
        k.push_back(input);
    }
    for (int i = 0; i < n; i++)
    {
        counter = 0;
        for (int j = 0; j < k[i]; j++)
        {
            cin >> input;
            counter += ((5 * input) + 15);
        }
        data.insert(counter);
    }
    cout << *data.begin();
    return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt","r",stdin);
        freopen ("output.txt","w",stdout);
    #endif

    int n,k[101]={0},m[101]={0},ans[101]={0};

    cin >> n;
    for(int i=0;i<n;i++)
        cin >> k[i];
    for(int j=0;j<n;j++){
        for(int i=0;i<k[j];i++){
            cin >> m[i];
            ans[j]+=(m[i]*5);
        }
        ans[j]+=15*(k[j]);
    }
    int min=10000;
    for(int i=0;i<n;i++) {
        if(min>ans[i]) min=ans[i];
    }
    cout << min;
    return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt","r",stdin);
        freopen ("output.txt","w",stdout);
    #endif

    int n,k[101]={0},m[101]={0},ans[101]={0};

    cin >> n;
    for(int i=0;i<n;i++)
        cin >> k[i];
    for(int j=0;j<n;j++){
        for(int i=0;i<k[j];i++){
            cin >> m[i];
            ans[j]+=(m[i]*5);
        }
        ans[j]+=15*(k[j]);
    }
    int min=10000000;
    for(int i=0;i<n;i++) {
        if(min>ans[i]) min=ans[i];
    }
    cout << min;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <sstream>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
typedef unsigned int uint;

#define mp make_pair
#define sqr(a) ((a)*(a))
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define forr(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define forit(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef vector<int> vint;
typedef vector<bool> vbool;
typedef vector<int64> vint64;
typedef vector<uint64> uvint64;
typedef pair<int, int> pii;
typedef pair<int64, int64> pii64;

template<typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p)
{
	in >> p.first >> p.second;
	return in;
}
template<typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p)
{
	out << p.first << " " << p.second;
	return out;
}
template<typename T>
istream& operator >> (istream& in, vector<T>& v)
{
	forn(i, v.size())
	{
		in >> v[i];
	}
	return in;
}
template<typename T>
ostream& operator << (ostream& out, vector<T>& v)
{
	forn(i, v.size())
	{
		out << v[i] << " ";
	}
	return out;
}

int main()
{
#ifdef LYZ_V
	freopen("ReadMe.txt", "r", stdin);
	//freopen("ReadMe.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	vint k(n);
	cin >> k;
	int res = 1e9;
	forn(i, n)
	{
		int t = 0;
		forn(j, k[i])
		{
			int a;
			cin >> a;
			t += a * 5 + 15;
		}
		res = min(t, res);
	}
	cout << res << endl;

	return 0;
}


#include <iostream>
#include <conio.h>

using namespace std;
int N;
int K[100];
int C[100];
int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>K[i];
		C[i]=0;
	}
	int D;
	for(int i=0;i<N;i++)
	{
		for(int o=0;o<K[i];o++)
		{
			cin>>D;
			C[i]+=D;
		}
		C[i]=C[i]*5+K[i]*15;

	}
	int Min=C[0];
	for(int i=1;i<N;i++)
	{
		if(Min>C[i])
		{
			Min=C[i];
		}
	}
	cout <<Min;
	return 0;
}


#include <iostream>
#include <conio.h>

using namespace std;
int N;
int K[100];
int C[100];
int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>K[i];
		C[i]=0;
	}
	int D;
	for(int i=0;i<N;i++)
	{
		for(int o=0;o<K[i];o++)
		{
			cin>>D;
			C[i]+=D;
		}
		C[i]=C[i]*5+K[i]*15;

	}
	int Min=C[0];
	for(int i=1;i<N;i++)
	{
		if(Min<C[i])
		{
			Min=C[i];
		}
	}
	cout <<Min;
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>
#include<set>
using namespace std;

bool f[2003][2003]={};

int main(){
    int n;
    int q[103]={};
    cin>>n;
    int ans=9999990;
    for(int i=0;i<n;i++)
        cin>>q[i];
    for(int i=0;i<n;i++){int t=0;
        for(int j=0;j<q[i];j++){
            int d;cin>>d;
            t+=d*5;
        }
        t+=q[i]*15;
        ans=min(t,ans);
    }
    cout<<ans;
    return 0;
}


#include<iostream>
using namespace std;

int main(){

	int n,a[100],b,min=10e10;
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>a[i];

	for (int i=0;i<n;i++){
		int sum=0;
		for (int j=0;j<a[i];j++)
			cin>>b,sum+=b*5+15;
		if (sum<min)
			min=sum;
	}

	cout<<min;
	return 0;
}


/*
ID: m.hamed1
PROG: wormhole
LANG: C++
*/
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<iterator>
#include<algorithm>
using namespace std;

int main()
{
	long long n,a,s=0,mn=1e6;
	cin>>n;
	vector<int>v(n);
	for(int i=0; i<n; ++i)
		cin>>v[i];
	for(int i=0; i<n; ++i)
	{
		s=0;
		for(int j=0; j<v[i]; ++j)
		{
			cin>>a;
			s+=a*5;
		}
		s+=v[i]*15;
		if(s<mn)mn=s;
	}
	cout<<mn;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int x,a[1000],i,j,p,s=0,z=0;
int main(){
    cin>>x;
	for(i=0;i<x;i++)cin>>a[i];
	for(i=0;i<x;i++){
		s=0;
		for(j=0;j<a[i];j++){
			cin>>p;
			s+=p*5+15;
		}
	    if(s<z || i==0)z=s;
	}
	cout<<z;
    return 0;
}


#include<iostream>
#include<set>
#include<map>
#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<math.h>
#include <iomanip>
#include<stack>
#include<queue>
#include<iomanip>
#include <sstream>
using namespace std;

int main()
{
	long long int n, k[100], mini =1000000, m, count=0 ;

	cin>>n ;
	for(int i=0 ; i<n; i++)
		cin>>k[i];
	for(int i=0 ; i<n; i++)
	{
		for(int j=0 ; j<k[i];j++)
		{
			cin>>m;
			count+=m*5;
		}
		count+=k[i]*15;
		mini=min(mini, count);
		count=0;
	}

	cout<<mini;

	return 0;

}


#include <vector>
#include <iostream>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
#include <limits>

#define INF  std::numeric_limits<int>::max();
using namespace std;

int main()
    {

#ifndef RELAX
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int min = INF;
    int n,count;
    vector<vector<int>> matr;

    cin>>n;
    int *size = new int[n];

    for(int i=0;i<n;i++){
        cin>>size[i];
        }

    for(int i=0;i<n;i++){

        count=0;

        for(int j = 0; j<size[i];j++){
            int x;
            cin>>x;
            count+=5*x;

            }
        count += 15*size[i];
        if( count<min) min = count;

        }

    cout<<min;
    return 0;
    }


#include <vector>
#include <iostream>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
#include <limits>

#define INF  std::numeric_limits<int>::max();
using namespace std;

int main()
    {

#ifndef RELAX
   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
#endif

    int min = INF;
    int n,count;
    vector<vector<int>> matr;

    cin>>n;
    int *size = new int[n];

    for(int i=0;i<n;i++){
        cin>>size[i];
        }

    for(int i=0;i<n;i++){

        count=0;

        for(int j = 0; j<size[i];j++){
            int x;
            cin>>x;
            count+=5*x;

            }
        count += 15*size[i];
        if( count<min) min = count;

        }

    cout<<min;
    return 0;
    }


#include<iostream>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		int a[101];
		for(int i=0;i<n;++i)
		{
			cin>>a[i];
		}
		int sum=0;
		int min=100000;
		for(int i=0;i<n;++i)
		{
			sum=0;
			for(int j=0;j<a[i];++j)
			{
				int b;
				cin>>b;
				sum+=b;
			}
			if(sum*5+a[i]*15<min)
				min=sum*5+a[i]*15;
		}
		cout<<min<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
using namespace std;
#define fo(a,b) for(int i = a;i<b;i++)
#define ll long long
#define N 50015

int main()
{
	int n, a[100], m, ans = N;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
	{
		int temp = 0;
		for (int j = 0; j < a[i]; j++)
		{
			cin >> m;
			temp += m * 5 + 15;
		}
		ans = min(temp, ans);
	}
	cout << ans;
	//system("pause");
}


#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
using namespace std;
#define fo(a,b) for(int i = a;i<b;i++)
#define ll long long
#define N 1e6

int main()
{
	int n, a[100], m, ans = N;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
	{
		int temp = 0;
		for (int j = 0; j < a[i]; j++)
		{
			cin >> m;
			temp += m * 5 + 15;
		}
		ans = min(temp, ans);
	}
	cout << ans;
	//system("pause");
}


#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cmath>
#include <algorithm>
#include<set>
#include<queue>
#include <typeinfo>
#include <deque>
#include <stack>
#include <iomanip>
using namespace std;
#define ll long long

int main()
{
	int n,k ; cin>>n; ;  vector<int> v; v.resize(n); int sum1=111111111,sum=0;
	for (int i = 0; i < n; i++){cin>>v[i];}

	for (int i = 0; i < n; i++)
	{
		sum=0;
		sum=v[i]*15;
		for (int j = 0; j < v[i]; j++)
		{
			int m; cin>>m;
			sum=sum+(m*5);
		}
		if(sum<sum1){sum1=sum;}
	}
	cout<<sum1<<endl;

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<set>
using namespace std;
void main() {
	int n,p, q, l, r,k=0, a[100] = { 0 }, b[100] = { 0 }, c[100] = { 0 }, d[100] = { 0 };
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < b[i]; j++) {
			cin >> l;
			a[i] += 5 * l;
		}
		a[i] += b[i] * 15;
	}
	sort(a, a + n);
	cout << a[0];
//system("pause");
}


#include <iostream>
using namespace std;
void main()
{
    int n, x, min = 101; cin >> n;
    int*s = new int[n], *m = new int[n];
    for (int i = 0; i < n; i++)
        cin >> m[i];
    for (int i = 0; i < n; i++)
            s[i] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m[i]; j++)
        {
            cin>> x;
            s[i] = s[i] + (x * 5) + 15;
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (s[i] < min)
            min = s[i];
    }
    cout << min;
}


#include <iostream>
using namespace std;
void main()
{
    int n, x, min = 1000001; cin >> n;
    int*s = new int[n], *m = new int[n];
    for (int i = 0; i < n; i++)
        cin >> m[i];
    for (int i = 0; i < n; i++)
            s[i] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m[i]; j++)
        {
            cin>> x;
            s[i] = s[i] + (x * 5) + 15;
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (s[i] < min)
            min = s[i];
    }
    cout << min;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, k[100], m,sum=0,min;
	vector<int> vec;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> k[i];
		}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < k[i]; j++){
			cin >> m;
			sum += m * 5;
		}
		sum += k[i] * 15;
		vec.push_back(sum);
		sum = 0;
	}
	min = vec[0];
	for (int i = 1; i < vec.size(); i++){
		if (vec[i] < min){
			min = vec[i];
		}
	}
	cout << min;
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int k[1001];
    int tong;
    int ss;

    int min = 1000000000;
    for(int i = 0; i < n; i++)
    {
        cin >> k[i];
    }

    for(int i = 0; i < n; i++)
    {
        tong = 0;
        for(int j = 0; j < k[i]; j++)
        {
            cin >> ss;
            tong += ss;
        }
        tong = tong * 5 + k[i] * 15;
        if(min > tong)
        {
            min = tong;
        }
    }

    cout << min;
}


#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int k[1001];
    int tong[101];
    int ss;

    int min = 1000000000;
    for(int i = 0; i < n; i++)
    {
        cin >> k[i];
    }

    for(int i = 0; i < n; i++)
    {
        tong[i] = 0;
        for(int j = 0; j < k[i]; j++)
        {
            cin >> ss;
            tong[i] += ss;
        }
        tong[i] = tong[i] * 5 + k[i] * 15;
        if(min > tong[i])
        {
            min = tong[i];
        }
    }

    cout << min;
}


#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> k(n);
    for (int i=0;i<n;i++)
    {
        cin>>k[i];
    }
    int max=100000000;
    for (int i=0;i<n;i++)
    {
        int s=0;
        for(int j=0;j<k[i];j++)
        {
            int a;
            cin>>a;
            s+=a*5;
            s+=15;
        }
        if (s<max)
            max=s;
    }
    cout<<max;
    return 0;
}


#include <iostream>
using namespace std;
void main()
{
int n;
cin>>n;
int a[100];
int b[100][100];
int sum = 0;
int min = 1000000;
for (int i=0;i<n;i++)
cin>>a[i];
for (int i=0;i<n;i++){
for (int j=0;j<a[i];j++){
cin>>b[i][j];
sum = sum + (b[i][j]*5);
sum+=15;
}
if (sum < min) min = sum ;
sum = 0;
}
cout<<min;
}


#include <iostream>
using namespace std;
void main()
{
int n;
cin>>n;
int a[100];
int b[100][100];
int sum = 0;
int min = 1000;
for (int i=0;i<n;i++)
cin>>a[i];
for (int i=0;i<n;i++){
for (int j=0;j<a[i];j++){
cin>>b[i][j];
sum = sum + (b[i][j]*5);
sum+=15;
}
if (sum < min) min = sum ;
sum = 0;
}
cout<<min;
}


#include <iostream>
#include <cstring>
using namespace std;

int main()
{
  int n;
  while(cin>>n)
  { int people[100],b[100],product[100][100],T=0;
    int i,j,k,p,num,time,temp;
    for(i=0;i<n;i++)
       cin>>people[i];
     //memset(time,0,sizeof(time));
    for(j=0;j<n;j++)
    {
       time=0;
      for(k=0;k<people[j];k++)
      {
        cin>>product[j][k];
        time=time+product[j][k]*5+15;
        //cout<<time<<endl;
        b[T]=time;
     }
      T++;
      //cout<<b[T-1]<<endl;
   }
   temp=b[0];
   for(p=1;p<n;p++)
   {
    if(b[p]<temp) temp=b[p];
   }
   cout<<temp<<endl;
  }
  return 0;
}


#include <iostream>
using namespace std;
int main()
{
  int n;
  while(cin>>n)
  { int a[100],b[100],c[100][100],T=0;
    int i,j,k,p,num,time,temp;
    for(i=0;i<n;i++)
       cin>>a[i];
    for(j=0;j<n;j++)
    {
       time=0;
      for(k=0;k<a[j];k++)
      {
        cin>>c[j][k];
        time=time+c[j][k]*5+15;
     }
      //time=a[j]*15+num*5;
      b[T++]=time;
   }
   temp=b[0];
   for(p=1;p<=T;p++)
   {
    if(b[p]<temp) temp=b[p];
   }
   cout<<temp<<endl;
  }
  return 0;
}


#include <iostream>
using namespace std;
int main()
{
  int a[100],b[100],c[100][100],T=0;
  int i,j,n,k,p,num,time,temp;
  cin>>n;
  for(i=0;i<n;i++)
     cin>>a[i];
  for(j=0;j<n;j++)
  {
    num=0;time=0;
    for(k=0;k<a[j];k++)
    {
      cin>>c[j][k];
      num+=c[j][k];
    }
    time=a[j]*15+num*5;
    b[T++]=time;
  }
  temp=b[0];
  for(p=1;p<=T;p++)
  {

    if(b[p]<temp) temp=b[p];
  }
  cout<<temp<<endl;
  return 0;
}


#include <iostream>
using namespace std;
int main()
{
  int n;
  while(cin>>n)
  { int people[100],b[100],product[100][100],T=0;
    int i,j,k,p,num,time,temp;
    for(i=0;i<n;i++)
       cin>>people[i];
    for(j=0;j<n;j++)
    {
       time=0;
      for(k=0;k<people[j];k++)
      {
        cin>>product[j][k];
        time=time+product[j][k]*5+15;
     }
      b[T++]=time;
   }
   temp=b[0];
   for(p=1;p<=T;p++)
   {
    if(b[p]<temp) temp=b[p];
   }
   cout<<temp<<endl;
  }
  return 0;
}


#include <iostream>
using namespace std;

int main()
{
  int n;
  while(cin>>n)
  { int people[100],b[100],product[100][100],T=0;
    int i,j,k,p,num,time,temp;
    for(i=0;i<n;i++)
       cin>>people[i];
     //memset(time,0,sizeof(time));
    for(j=0;j<n;j++)
    {
       time=0;
      for(k=0;k<people[j];k++)
      {
        cin>>product[j][k];
        time=time+product[j][k]*5+15;
     }
     b[T++]=time;
   }
   temp=b[0];
   for(p=1;p<n;p++)
   {
    if(b[p]<temp) temp=b[p];
   }
   cout<<temp<<endl;
  }
  return 0;
}


#include <iostream>
using namespace std;
int main()
{
  int n;
  while(cin>>n)
  { int a[100],b[100],c[100][100],T=0;
    int i,j,k,p,num,time,temp;
    for(i=0;i<n;i++)
       cin>>a[i];
    for(j=0;j<n;j++)
    {
      num=0;time=0;
      for(k=0;k<a[j];k++)
      {
        cin>>c[j][k];
        num+=c[j][k];
     }
      time=a[j]*15+num*5;
      b[T++]=time;
   }
   temp=b[0];
   for(p=1;p<=T;p++)
   {
    if(b[p]<temp) temp=b[p];
   }
   cout<<temp<<endl;
  }
  return 0;
}


#include <iostream>
using namespace std;
int main()
{
  int a[100],b[100],c[100][100],T=0;
  int i,j,n,k,p,num,time,temp;
  cin>>n;
  for(i=0;i<n;i++)
     cin>>a[i];
  for(j=0;j<n;j++)
  {
    num=0;time=0;
    for(k=0;k<a[j];k++)
    {
      cin>>c[j][k];
      num+=c[j][k];
    }
    time=a[j]*15+num*5;
    b[T]=time;T++;
  }
  for(p=1;p<=T;p++)
  {
     temp=b[0];
    if(b[p]<temp) temp=b[p];
  }
  cout<<temp<<endl;
  return 0;
}


#include <iostream>
using namespace std;
int main()
{
  int n;
  while(cin>>n)
  { int a[100],b[100],c[100][100],T=0;
    int i,j,k,p,num,time,temp;
    for(i=0;i<n;i++)
       cin>>a[i];
    for(j=0;j<n;j++)
    {
      num=0;time=0;
      for(k=0;k<a[j];k++)
      {
        cin>>c[j][k];
        num+=c[j][k];
     }
      time=a[j]*15+num*5;
      b[T++]=time;
   }
   temp=b[0];
   for(p=1;p<=T;p++)
   {

    if(b[p]<temp) temp=b[p];
   }
   cout<<temp<<endl;
   temp=0;
  }
  return 0;
}


#include <iostream>
#include <cstring>
using namespace std;

int main()
{
  int n;
  while(cin>>n)
  { int people[100],time[100],product[100][100];
    int i,j,k,p,num,temp;
    for(i=0;i<n;i++)
       cin>>people[i];
     memset(time,0,sizeof(time));
    for(j=0;j<n;j++)
    {
       //time=0;
      for(k=0;k<people[j];k++)
      {
        cin>>product[j][k];
        time[j]=time[j]+product[j][k]*5+15;
        //cout<<time<<endl;
     }
      //b[T++]=time;
      //cout<<b[T-1]<<endl;
   }
   temp=time[0];
   for(p=1;p<n;p++)
   {
    if(time[p]<temp) temp=time[p];
   }
   cout<<temp<<endl;
  }
  return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int main()
{int n,k[101],m,sum=0,min=0;
  cin>>n;
  for(int i=0;i<n;i++)
  {cin>>k[i];}
  for(int i=0;i<n;i++)
 { if(i==0)for(int j=0;j<k[i];i++){cin>>m;min+=m*5+k[i]*15;}
 sum=0;
   for(int j=0;j<k[i];j++)
   {
     cin>>m;
     sum+=m*5;
     }
sum+=k[i]*15;
   if(sum<min)min=sum;
   }
  cout<<min<<endl;
 return 0; }


#include <iostream>
using namespace std;
int main()
{int n,k[101],m,sum=0,min=1000;
  cin>>n;
  for(int i=0;i<n;i++)
  {cin>>k[i];}
  for(int i=0;i<n;i++)
 {  sum=0;
   for(int j=0;j<k[i];j++)
   {
     cin>>m;
     sum+=m*5;
     }
sum+=n*15;
   if(sum<min)min=sum;
   }
  cout<<min<<endl;
 return 0; }


#include <iostream>
#include <math.h>
using namespace std;
int main()
{int n,k[101],m[101],mini,sum=0;
    cin>>n;

    for(int i=0;i<n;i++)//number of cashiers
    {cin>>k[i];}//numbers of people on each cash

    for(int i=0;i<n;i++)
    {
        sum=0;
        for (int j=0;j<k[i];j++)
        {

            cin>>m[j];
            sum+=15+m[j]*5;
            if(i==0)mini=sum;
        }
        mini=min(mini,sum);
    }
    cout<<mini<<endl;
    return 0; }


#include<iostream>
using namespace std;
int main()
{

	int y;
	cin>>y;
	int *sum=new int[y];
	int *p=new int[y];
	for(int i=0;i<y;i++)
	{
		cin>>p[i];

	}
	for(int i=0;i<y;i++)
	{
		sum[i]=0;
	}
	int **x=new int *[y];
	for(int i=0;i<y;i++)
	{

		x[i]=new int [p[i]];
		for(int j=0;j<p[i];j++)
		{
			cin>>x[i][j];
			sum[i]+=(5*x[i][j]);
		}
		sum[i]+=15*p[i];
	}
	int min=sum[0];
	for(int i=1; i<y;i++)
		if(sum[i]<=min)
	min=sum[i];
	cout<<min;

	return 0;
}


// code1.cpp: ���������� ����� ����� ��� ����������� ����������.
//

#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n,k,rr=0,temp=0;
	cin >> n;
	vector<int> arr;
	vector<int> res;
	for (int i =0; i < n; i++)
	{
		cin >> k;
		arr.push_back(k);
	}
	for (int i =0; i < n; i++)
	{
		for(int j = 0; j < arr[i];j++)
		{
				cin >> k;
				rr+=k*5;
		}
		rr+= arr[i]*15;
		res.push_back(rr);
		rr=0;
	}
	temp = res[0];

	for(int i=1; i < n; i++)
		if(res[i] < res[i-1])
		temp = res[i];
	cout<<temp;

	return 0;
}


// code1.cpp: ���������� ����� ����� ��� ����������� ����������.
//

#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n,k,rr=0,temp=0;
	cin >> n;
	vector<int> arr;
	vector<int> res;
	for (int i =0; i < n; i++)
	{
		cin >> k;
		arr.push_back(k);
	}
	for (int i =0; i < n; i++)
	{
		for(int j = 0; j < arr[i];j++)
		{
				cin >> k;
				rr+=k*5;
		}
		rr+= arr[i]*15;
		res.push_back(rr);
		//cout << res[i];
		rr=0;
	}
	temp = res[0];

	for(int i=1; i < n; i++)
		if(res[i] < res[i-1])
		temp = res[i];
	cout<<temp;

	return 0;
}


// code1.cpp: ���������� ����� ����� ��� ����������� ����������.
//

#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n,k,rr=0,temp=0;
	cin >> n;
	vector<int> arr;
	vector<int> res;
	for (int i =0; i < n; i++)
	{
		cin >> k;
		arr.push_back(k);
	}
	for (int i =0; i < n; i++)
	{
		for(int j = 0; j < arr[i];j++)
		{
				cin >> k;
				rr+=k*5;
		}
		rr+= arr[i]*15;
		res.push_back(rr);
		rr=0;
	}
	temp = res[0];

	for(int i=1; i < n; i++)
		if(res[i] < res[i-1])
		temp = res[i];
	cout<<temp;
	getchar();
	getchar();
	return 0;
}


// code1.cpp: ���������� ����� ����� ��� ����������� ����������.
//

//#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n,k,rr=0,temp=0;
	cin >> n;
	vector<int> arr;
	vector<int> res;
	for (int i =0; i < n; i++)
	{
		cin >> k;
		arr.push_back(k);
	}
	for (int i = 0; i < n; i++)
	{
		for(int j = 0; j < arr[i];j++)
		{
				cin >> k;
				rr+=k*5;
		}
		rr+= arr[i]*15;
		res.push_back(rr);

		rr=0;
	}

	temp = res[0];

	for(int i=1; i < n; i++)
		if(res[i] < temp)
		temp = res[i];
	cout<<temp;
	//getchar();
	//getchar();
	return 0;
}


// code1.cpp: ���������� ����� ����� ��� ����������� ����������.
//

#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	int n,k,rr=0,temp=0;
	cin >> n;
	vector<int> arr;
	vector<int> res;
	for (int i =0; i < n; i++)
	{
		cin >> k;
		arr.push_back(k);
	}
	for (int i =0; i < n; i++)
	{
		for(int j = 0; j < arr[i];j++)
		{
				cin >> k;
				rr+=k*5;
		}
		rr+= arr[i]*15;
		res.push_back(rr);
		//cout << res[i];
		rr=0;
	}
	temp = res[0];

	for(int i=1; i < n; i++)
		if(res[i] < res[i-1])
		temp = res[i];
	cout<<temp;
	return 0;
}


// code1.cpp: ���������� ����� ����� ��� ����������� ����������.
//

//#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n,k,rr=0,temp=0;
	cin >> n;
	vector<int> arr;
	vector<int> res;
	for (int i =0; i < n; i++)
	{
		cin >> k;
		arr.push_back(k);
	}
	for (int i = 0; i < n; i++)
	{
		for(int j = 0; j < arr[i];j++)
		{
				cin >> k;
				rr+=k*5;
		}
		rr+= arr[i]*15;
		res.push_back(rr);

		rr=0;
	}
	for (int i = 0; i < n; i++)
		cout << res[i]<< "  ";
	temp = res[0];

	for(int i=1; i < n; i++)
		if(res[i] < temp)
		temp = res[i];
	cout<<temp;
	//getchar();
	//getchar();
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	int r[100];
	int a[100];
	cin>>n;
	int mn=10000000;
	for(int i=0;i<n;i++){
		cin>>a[i];
		r[i]=a[i]*3;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<a[i];j++){
			int b;
			cin>>b;
			r[i]+=b;
		}
		mn=min(mn,r[i]);
	}
	cout<<mn*5;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int fcost[105];
    memset (fcost,0,sizeof(fcost));
    int vec[105];
    int n;
    cin>>n;
    for (int i=0;i<n;i++)
    {
        cin>>vec[i];
        fcost[i]+=15*vec[i];
    }
    int m;
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<vec[i];j++)
        {
            cin>>m;
            fcost[i]+=m*5;
        }
    }
    sort(fcost,fcost+n);
    cout<<fcost[0]<<endl;

}


#include "iostream"
using namespace std;

int main() {
	int nPers;
	int result = 0;
	int maxTime = 100000;
	int qStep = 0;
	int pr;
	cin >> nPers;
	int *mas = new int[nPers];
	for (int i = 0; i < nPers; i++) {
		cin >> mas[i];
	}
	for (int i = 0; i < nPers; i++) {
		for (int j = 0; j < mas[i]; j++) {
			cin >> pr;
			result += pr * 5;
			qStep += 1;
		}
		result += qStep * 15;
		if (result < maxTime) {
			maxTime = result;
		}
		result = 0;
		qStep = 0;
	}
	cout << maxTime;
	return 0;
}


#include "iostream"
using namespace std;

int main() {
	int n;
	int result = 0;
	int max = 100;
	int q = 0;
	int pr;
	cin >> n;
	int *mas = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> mas[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < mas[i]; j++) {
			cin >> pr;
			result += pr * 5;
			q += 1;
		}
		result += q * 15;
		if (result < max) {
			max = result;
		}
	}
	cout << max;
	return 0;
}


//============================================================================
// Name        : CF.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>
#include<queue>
#include <sstream>
#include<stdio.h>
using namespace std;
int gcd(int a, int b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
    }

int main() {
    int n,b,ans,a=0;
    int arr[150];
    cin>>n;

    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }

    for(int i=0;i<n;i++)
        {
        a=0;
        for(int j=0;j<arr[i];j++)
        {
            cin>>b;
            a+=15+(5*b);
        }

        if(i==0)
            ans=a;
        else
        {
            if(a<ans)
            ans=a;
        }

        }

cout<<ans<<endl;

    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
#define MAXN 1000
#define INF 100000000

int main()
{
    int min = INF, N, x, i, j;
    int a[MAXN];

    cin >> N;

    for(i=0; i<N; i++)
        cin >> a[i];

    for(i=0; i<N; i++)
    {

        int sum = 0;
        for(j=0; j<a[i]; j++)
        {
            cin >> x;
            sum += x * 5;
        }
        sum += a[i] * 15;

        if(min > sum)
            min = sum;
    }

    cout << min <<endl;

    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
#define MAXN 1000
#define INF 100000000

int main()
{
	int min = INF, N, x;
	int a[MAXN];

	cin >> N;

	for(int i=0; i<N; i++)
		cin >> a[i];

	for(i=0; i<N; i++)
	{

		int sum = 0;
		for(int j=0; j<a[i]; j++)
		{
			cin >> x;
			sum += x * 5;
		}
		sum += a[i] * 15;

		if(min > sum)
			min = sum;
	}

	cout << min <<endl;

	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>

using namespace std;

int k[1000];

int main()
{
	int n,m;
	std::cin >> n;
	int solve = 2000000000;
	for ( int i = 0 ; i < n ; ++i )
		std::cin >> k[i];
	for ( int i = 0 ; i < n ; ++i )
	{
		int value = 0 ;
		for ( int j = 0 ; j < k[i] ; ++j )
		{
			std::cin >> m;
			value = value +5*m+15;
		}
		if ( solve > value )
		{
			solve = value;
		}
	}
	std::cout << solve << std::endl;
}


#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>

using namespace std;

int main()
{
	int n,m,k;
	std::cin >> n;
	int solve = 2000000000;
	for ( int i = 0 ; i < n ; ++i )
	{
		int value = 0 ;
		std::cin >> k;
		for ( int j = 0 ; j < k ; ++j )
		{
			std::cin >> m;
			value = value +5*m+15;
		}
		if ( solve > value )
		{
			solve = value;
		}
	}
	std::cout << solve << std::endl;
}


#include<iostream>
#include<string>
#include<cmath>
#include<cctype>
#include<vector>
#include<sstream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[100];
	int b[100][100];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<a[i];j++){
			cin>>b[i][j];
		}
	}
	int c[100];
	for(int i=0;i<n;i++){
		int y=0;
		for(int j=0;j<a[i];j++){
			y+=b[i][j]*5+15;
		}
		c[i]=y;
	}
	int mini=c[0];
	for(int i=1;i<n;i++){
		if(mini>c[i]){
			mini=c[i];
		}
	}
	cout<<mini;

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <ctime>

using namespace std;

#define VI vector<int>
#define VVI vector<VI >
#define VB vector<bool>
#define VVB vector<VB >
#define VS vector<string>
#define PII pair<int, int>
#define VPII vector<pair<int, int> >
#define REP(var, startFrom, endTo) for(int var = startFrom; var < (int)endTo; ++var)

template <typename T>
inline const T MAX(T a, T b) { return ((a) > (b) ? (a) : (b)); }
template <typename T>
inline const T MIN(T a, T b) { return ((a) > (b) ? (b) : (a)); }
template <typename T>
inline const T ABS(T a) { return (((a) > 0) ? (a) : (-(a))); }

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	int n;
	cin >> n;

	VI cashiers = VI(n);
	REP(i, 0, n)
		cin >> cashiers[i];

	int ans = INT_MAX;
	REP(i, 0, n)
	{
		int sum = 0;
		REP(j, 0, cashiers[i])
		{
			int num;
			cin >> num;

			sum += num;
		}

		int val = (cashiers[i] * 15) + (sum * 5);
		if (val < ans)
			ans = val;
	}

	cout << ans << endl;

	return 0;
}


#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
using namespace std;
#define ll long long
#define maxn 200005
#define INF 0x3f3f3f3f
#define MST(vis,x) memset(vis,x,sizeof(x))
int s1[maxn];
int suml[maxn],sumr[maxn];
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		int ma=-INF,mi=INF;
		for(int a=1;a<=n;a++)
		{
			scanf("%d",&s1[a]);
			ma=max(ma,s1[a]);
			mi=min(mi,s1[a]);
		}
		if(m==1)
		{
			printf("%d\n",mi);
		}
		else if(m==2)
		{
			if(s1[1]==ma||s1[n]==ma)
				printf("%d\n",ma);
			else
			{
				int finama=-INF;
				MST(suml,INF);
				MST(sumr,INF);
				for(int a=1;a<=n;a++)
					suml[a]=min(suml[a-1],s1[a]);
				for(int a=n;a>=1;a--)
					sumr[a]=min(sumr[a+1],s1[a]);
				for(int a=1;a<n;a++)
				{
					finama=max(finama,max(suml[a],sumr[a+1]));
				}
				printf("%d\n",finama);
			}
		}
		else if(m>=3)
			printf("%d\n",ma);

	}
	return 0;
}


#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
using namespace std;
#define ll long long
#define maxn 200005
#define INF 0x3f3f3f3f
#define MST(vis,x) memset(vis,x,sizeof(x))
int s1[maxn];
int suml[maxn],sumr[maxn];
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		int ma=-INF,mi=INF;
		for(int a=1;a<=n;a++)
		{
			scanf("%d",&s1[a]);
			ma=max(ma,s1[a]);
			mi=min(mi,s1[a]);
		}
		if(m==1)
		{
			printf("%d\n",mi);
		}
		else if(m==2)
		{
			if(s1[1]==ma||s1[n]==ma)
				printf("%d\n",ma);
			else
			{
				printf("%d\n",max(s1[1],s1[n]);
//				int finama=-INF;
//				suml[0]=INF;
//				sumr[n+1]=INF;
//				for(int a=1;a<=n;a++)
//					suml[a]=min(suml[a-1],s1[a]);
//				for(int a=n;a>=1;a--)
//					sumr[a]=min(sumr[a+1],s1[a]);
//				for(int a=1;a<n;a++)
//				{
//					finama=max(finama,max(suml[a],sumr[a+1]));
//				}
//				printf("%d\n",finama);
			}
		}
		else if(m>=3)
			printf("%d\n",ma);

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k,x,minm=1e11,maxm=-1e11,minm1=1e11,minm2=1e11,a[100005],indx,indx1;
    cin>>n>>k;
    for(ll i=0;i<n;i++)
    {
        cin>>x;a[i]=x;
        if(x>maxm){
            maxm=x;indx1=i;}
        if(x<minm){
            minm=x;indx=i;}
    }
    if(k==1)
        cout<<minm<<endl;

           else if(k==2)
            {
                        if(minm==a[0])
                        {
                             minm1=a[0];
                        for(ll j=indx1;j<n;j++)
                            minm2=min(minm2,a[j]);
                        }
                        else if(minm=a[n-1])
                        {
                             minm1=a[n-1];
                        for(ll j=indx1;j>=0;j--)
                            minm2=min(minm2,a[j]);
                        }
                        else{

                        for(ll i=0;i<=indx;i++)
                            minm1=min(minm1,a[i]);
                        for(ll j=indx+1;j<n;j++)
                            minm2=min(minm2,a[j]);}
                        cout<<max(minm1,minm2)<<endl;
            }

            else
                cout<<maxm<<endl;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k,x,minm=1e11,maxm=-1e11;
    cin>>n>>k;
    for(ll i=0;i<n;i++)
    {
        cin>>x;
        minm=min(minm,x);
        maxm=max(maxm,x);
    }
    if(k==1)
        cout<<minm<<endl;
    else
        cout<<maxm<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k,x,minm=1e11,maxm=-1e11,minm1=1e11,minm2=1e11,a[100005],indx;
    cin>>n>>k;
    for(ll i=0;i<n;i++)
    {
        cin>>x;a[i]=x;
        maxm=max(maxm,x);
        if(x<minm){
            minm=x;indx=i;}
    }
    if(k==1)
        cout<<minm<<endl;

           else if(k==2)
            {

                        for(ll i=0;i<=indx;i++)
                            minm1=min(minm1,a[i]);
                        for(ll j=indx+1;j<n;j++)
                            minm2=min(minm2,a[j]);
                        cout<<max(minm1,minm2)<<endl;}

            else
                cout<<maxm<<endl;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k,x,minm=1e11,maxm=-1e11,minm1=1e11,minm2=1e11,a[100005],indx,indx1;
    cin>>n>>k;
    for(ll i=0;i<n;i++)
    {
        cin>>x;a[i]=x;
        if(x>maxm){
            maxm=x;indx1=i;}
        if(x<minm){
            minm=x;indx=i;}
    }
    if(k==1)
        cout<<minm<<endl;

           else if(k==2)
            {
                        if(minm==a[0])
                        {
                             minm1=a[0];
                        for(ll j=indx1;j<n;j++)
                            minm2=min(minm2,a[j]);
                        }
                        else if(minm=a[n-1])
                        {
                             minm1=a[n-1];
                        for(ll j=indx1;j>=0;j--)
                            minm2=min(minm2,a[j]);
                        }
                        else{

                        for(ll i=0;i<indx;i++)
                            minm1=min(minm1,a[i]);
                        for(ll j=indx+1;j<n;j++)
                            minm2=min(minm2,a[j]);}
                        cout<<max(minm1,minm2)<<endl;
            }

            else
                cout<<maxm<<endl;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k,x,a[100005],minm=1e11,maxm=-1e11,ans=-1e11,pre[100005],suff[100005];
    cin>>n>>k;
    for(ll i=0;i<n;i++)
    {
        cin>>x;a[i]=x;
       minm=min(minm,a[i]);
       maxm=max(maxm,a[i]);
    }
    if(k==1)
        cout<<minm<<endl;

           else if(k==2)
            {
                pre[0]=a[0];
                suff[n-1]=a[n-1];
                for(ll i=1;i<n-1;i++)
                    pre[i]=min(pre[i-1],a[i]);
                for(ll i=n-2;i>0;i--)
                    suff[i]=min(suff[i+1],a[i]);

                for(ll i=0;i<n-1;i++)
                    ans=max(ans,max(pre[i],suff[i+1]));
                cout<<ans<<endl;

            }

            else
                cout<<maxm<<endl;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k,x,minm=1e11,maxm=-1e11,minm1=1e11,minm2=1e11,a[100005],indx;
    cin>>n>>k;
    for(ll i=0;i<n;i++)
    {
        cin>>x;a[i]=x;
        maxm=max(maxm,x);
        if(x<minm){
            minm=x;indx=i;}
    }
    if(k==1)
        cout<<minm<<endl;
    else{
            if(k==2)
            {
                if(maxm!=a[0] && maxm!=a[n-1])
                    {
                        //cout<<indx<<endl;
                        if(indx==0)
                            cout<<a[n-1];
                        else if(indx==n-1)
                            cout<<a[0];
                        else{
                        for(ll i=0;i<=indx;i++)
                            minm1=min(minm1,a[i]);
                        for(ll j=indx+1;j<n;j++)
                            minm2=min(minm2,a[j]);
                        cout<<max(minm1,minm2)<<endl;}
                    }
                    else
                        cout<<maxm<<endl;

            }
            else
                cout<<maxm<<endl;
}
}


#include <bits/stdc++.h>
using namespace std;
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
*/
#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))

#define fastio() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file() freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define nl "\n"
#define sp " "

template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

typedef long long ll;
typedef pair<int,int> pii;

const int N = 1e5+5;

int tc = 1;

int ara[N], n, k;

int main(){

    //file();

    fastio();

    //cin >> tc;

    while(tc--){

        cin >> n >> k;

        for(int  i = 0; i < n; i++)
            cin >> ara[i];

        sort(ara, ara+n);

        if(k == 1)
            cout << ara[0] << nl;
        else{

            k--;
            cout << ara[n-k] << nl;
        }

    }

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
*/
#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))

#define fastio() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file() freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define nl "\n"
#define sp " "

template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

typedef long long ll;
typedef pair<int,int> pii;

const int N = 1e5+5;

int tc = 1;

int ara[N], n, k;

int main(){

    //file();

    fastio();

    //cin >> tc;

    while(tc--){

        cin >> n >> k;

        for(int  i = 0; i < n; i++)
            cin >> ara[i];

        sort(ara, ara+n);

        if(k == 1)
            cout << ara[0] << nl;
        else
            cout << ara[n-1] << nl;

    }

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
*/
#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))

#define fastio() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file() freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define nl "\n"
#define sp " "

template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

typedef long long ll;
typedef pair<int,int> pii;

const int N = 1e5+5;

int tc = 1;

int x, n, k, ans, ara[N];

int main(){

    //file();

    fastio();

    //cin >> tc;

    while(tc--){

        cin >> n >> k;

        for(int  i = 0; i < n; i++){
            cin >> ara[i];
        }

        if(k==2){
            int mn1 = ara[0];

            for(int i =  1; i < n; i++){
                if(ara[i] < mn1)
                    break;
            }

            int mn2 = ara[n-1];
            for(int i = n-2; i >= 0; i--){
                if(ara[i] < mn2)
                    break;
            }

            cout << max(mn1, mn2) << nl;
            continue;
        }

        sort(ara, ara+n);

        if(k == 1)
            cout << ara[0]<< nl;
        else
            cout << ara[n-1] << nl;
    }

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
*/
#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))

#define fastio() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file() freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define nl "\n"
#define sp " "

template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

typedef long long ll;
typedef pair<int,int> pii;

const int N = 1e5+5;

int tc = 1;

int n, k, ans, ara[N], mn1, mn2;

int main(){

    //file();

    fastio();

    //cin >> tc;

    while(tc--){

        cin >> n >> k;

        for(int  i = 0; i < n; i++){
            cin >> ara[i];
        }

        if(k==2){
            int mn1 = ara[0];

            for(int i =  1; i < n; i++){
                if(ara[i] < mn1)
                    break;
            }

            int mn2 = ara[n-1];
            for(int i = n-2; i >= 0; i--){
                if(ara[i] < mn2)
                    break;
            }

            cout << max(mn1, mn2) << nl;
            continue;
        }

        mn1 = mn2 = ara[0];

        for(int i = 1; i < n; i++){
            if(ara[i] < mn1)
                mn1 = ara[i];
            if(ara[i] > mn2)
                mn2 = ara[i];
        }

        if(k == 1)
            cout << mn1<< nl;
        else
            cout << mn2 << nl;
    }

    return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

int res = INT_MIN, q = INT_MAX, n, t, y;

int main(){
    cin >> n >> y;

    for (int i = 0; i < n; i++){
        cin >> t;
        res = max(res, t);
        q = min(q, t);
    }

    cout << (y == 1 ? q : res);
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

int a[100001];
int res = INT_MIN, q = INT_MAX, n, t, y, best = INT_MIN, w = INT_MAX;

int main(){
    cin >> n >> y;

    for (int i = 0; i < n; i++){
        cin >> a[i];
        res = max(res, a[i]);
        q = min(q, a[i]);
        w = min(w, a[i]);
        best = max(w, best);
    }

    w = INT_MAX;
    for (int i = n - 1; i >= 0; i--){
        w = min(w, a[i]);
        best = max(w, best);
    }

    cout << (y == 1 ? q : (y == 2 ? best : res));
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

int a[100001];
int res = INT_MIN, q = INT_MAX, n, t, y, best = INT_MIN, w = INT_MAX;

int main(){
    cin >> n >> y;

    for (int i = 0; i < n; i++){
        cin >> a[i];
        res = max(res, a[i]);
        q = min(q, a[i]);
        w = min(w, a[i]);
        best = max(w, best);
    }

    w = INT_MAX;
    for (int i = n - 1; i >= 0; i--){
        w = min(w, a[i]);
        best = max(w, best);
    }

    cout << (y == 1 ? q : (q == 2 ? best : res));
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

int a[100001];
int res = INT_MIN, q = INT_MAX, n, t, y, best = INT_MIN, w = INT_MAX;

int main(){
    cin >> n >> y;

    for (int i = 0; i < n; i++){
        cin >> a[i];
        res = max(res, a[i]);
        q = min(q, a[i]);
        w = min(w, a[i]);
        best = max(w, best);
    }

    w = INT_MAX;
    for (int i = n - 1; i >= 0; i--){
        w = min(w, a[i]);
        best = max(w, best);
    }

    cout << (y == 1 ? q : (q == 2 ? best : res)));
}


#include<bits/stdc++.h>
using namespace std;

int main () {
  int n, k;
  while (cin >> n >> k) {
    vector<int> values(n), prefix(n), suffix(n);
    for (auto &i : values) cin >> i;
    if (k == 1) {
      cout << *min_element(values.begin(), values.end()) << endl;
    } else if (k > 2) {
      cout << *max_element(values.begin(), values.end()) << endl;
    } else {
      prefix[0] = values[0];
      suffix[n - 1] = values[n - 1] ;

      for (int i = 1; i < n; i++) prefix[i] = min(prefix[i - 1], values[i]);
      for (int i = n - 2; i >= 0; i--) suffix[i] = min(suffix[i + 1], values[i]);
      int ans = 0;
      // for (int i = 0; i < n; i++) cout << prefix[i] << " "; cout << endl;
      // for (int i = 0; i < n; i++) cout << suffix[i] << " "; cout << endl;
      for (int i = 0; i < n - 1; i++) {
        ans = max(ans, max(prefix[i], suffix[i + 1]));
      }
      for (int i = n - 1; i > 0; i--) {
        ans = max(ans, max(prefix[i - 1], suffix[i]));
      }
      cout << ans << endl;
    }
  }
}


#include<bits/stdc++.h>
using namespace std;

int main () {
  int n, k;
  while (cin >> n >> k) {
    vector<int> values(n), prefix(n), suffix(n);
    for (auto &i : values) cin >> i;
    if (k == 1) {
      cout << *min_element(values.begin(), values.end()) << endl;
    } else if (k > 2) {
      cout << *max_element(values.begin(), values.end()) << endl;
    } else {
      prefix[0] = values[0];
      suffix[n - 1] = values[n - 1] ;

      for (int i = 1; i < n; i++) prefix[i] = min(prefix[i - 1], values[i]);
      for (int i = n - 2; i >= 0; i--) suffix[i] = min(suffix[i + 1], values[i]);
      int ans = 0;
      // for (int i = 0; i < n; i++) cout << prefix[i] << " "; cout << endl;
      // for (int i = 0; i < n; i++) cout << suffix[i] << " "; cout << endl;
      for (int i = 0; i < n - 1; i++) {
        ans = max(ans, max(prefix[i], suffix[i + 1]));
      }
      cout << ans << endl;
    }
  }
}


#include<bits/stdc++.h>
using namespace std;

int main () {
  int n, k;
  while (cin >> n >> k) {
    vector<int> values(n), prefix(n), suffix(n);
    for (auto &i : values) cin >> i;
    if (k == 1) {
      cout << *min_element(values.begin(), values.end()) << endl;
    } else if (k > 2) {
      cout << *max_element(values.begin(), values.end()) << endl;
    } else {
      prefix[0] = values[0];
      suffix[n - 1] = values[n - 1] ;

      for (int i = 1; i < n; i++) prefix[i] = min(prefix[i - 1], values[i]);
      for (int i = n - 2; i >= 0; i--) suffix[i] = min(suffix[i + 1], values[i]);
      int ans = 0;
      for (int i = 0; i < n; i++) {
        ans = max(ans, max(prefix[i], suffix[i]));
      }
      cout << ans << endl;
    }
  }
}


#include<bits/stdc++.h>
using namespace std;

int main () {
  int n, k;
  while (cin >> n >> k) {
    vector<int> values(n), prefix(n), suffix(n);
    for (auto &i : values) cin >> i;
    if (k == 1) {
      cout << *min_element(values.begin(), values.end()) << endl;
    } else if (k > 2) {
      cout << *max_element(values.begin(), values.end()) << endl;
    } else {
      prefix[0] = values[0];
      suffix[n - 1] = values[n - 1] ;

      for (int i = 1; i < n; i++) prefix[i] = min(prefix[i - 1], values[i]);
      for (int i = n - 2; i >= 0; i--) suffix[i] = min(suffix[i + 1], values[i]);
      int ans = -1000000007;
      for (int i = 0; i < n; i++) {
        ans = max(ans, max(prefix[i], suffix[i]));
      }

      cout << ans << endl;
    }
  }
}


#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin>> n;
    cin >> k;
    int minn=99999;
    int maxx = 0;
    if(k==1)
    {
        for (int i=0;i<n;i++){
            int t;
            cin >> t;
            minn=min(minn,t);
        }
        cout<<minn<<endl;
        return 0;
    }
    else{
        for (int i=0;i<n;i++){
            int t;
            cin >> t;
            maxx = max(maxx,t);
        }
        cout<<maxx<<endl;
        return 0;
    }

}


#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin>> n;
    cin >> k;
    long long  minn=999999999999999;
    int maxx = 0;
    if(k==1)
    {
        for (int i=0;i<n;i++){
             long long t;
            cin >> t;
            minn=min(minn,t);
        }
        cout<<minn<<endl;
        return 0;
    }
    else{
        for (int i=0;i<n;i++){
            int t;
            cin >> t;
            maxx = max(maxx,t);
        }
        cout<<maxx<<endl;
        return 0;
    }

}


#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin>> n;
    cin >> k;
    long long  minn=999999999;
    int maxx = 0;
    if(k==1)
    {
        for (int i=0;i<n;i++){
             long long t;
            cin >> t;
            minn=min(minn,t);
        }
        cout<<minn<<endl;
        return 0;
    }
    else{
        for (int i=0;i<n;i++){
            int t;
            cin >> t;
            maxx = max(maxx,t);
        }
        cout<<maxx<<endl;
        return 0;
    }

}


#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=1e5+10;
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin>> n;
    cin >> k;
    long long a[maxn];
    for (int i =0;i<n;i++){
        cin >>a[i];
    }
    if (k==2){
        cout<<max(a[0],a[n-1])<<endl;
        return 0;
    }
    else{
        sort(a,a+n);
        if(k==1)
            cout<<a[0]<<endl;
        else
            cout <<a[n-1]<<endl;

    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e7;
 ll a[maxn];
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin>> n;
    cin >> k;
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    if (k==1)
        cout <<a[0]<<endl;
    else
        cout <<a[n-1] <<endl;
}


#include <iostream>
#include <algorithm>
using namespace std;
int a[111111];
int zheng[111111],dao[111111];
int main()
{
	int n,k;
	cin >> n >>k;
	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	if(k==2)cout << max(a[n-1],a[0]);
			sort(a,a+n);
	if(k==1)cout << a[0]<< endl;
	else if (k==3) cout << a[n-1]<< endl;

}


#include <iostream>
#include <algorithm>
using namespace std;
int a[111111];
int zheng[111111],dao[111111];
int main()
{
	int n,k;
	cin >> n >>k;
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	if(k==2)cout << max(a[n-1],a[0]);
	sort(a,a+n);
	if(k==1)cout << a[0]<< endl;
	else if (k>=3) cout << a[n-1]<< endl;

}


#include <iostream>
#include <algorithm>
using namespace std;
int a[111111];
int zheng[111111],dao[111111];
int main()
{
	int n,k;
	cin >> n >>k;
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
		sort(a,a+n);
	if(k==2)cout << max(a[n-1],a[0]);
	if(k==1)cout << a[0]<< endl;
	else if (k==3) cout << a[n-1]<< endl;

}


#include <iostream>
#include <algorithm>
using namespace std;
int a[111111];
int zheng[111111],dao[111111];
int main()
{
	int n,k;
	cin >> n >>k;
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	if(k==2)
	{
		zheng[0]=a[0];
		for(int i=1;i<n;i++)
		{
			zheng[i]=min(zheng[i-1],a[i]);
		}
		dao[n-1]=a[n-1];
		for(int i=n-2;i>=0;i--)
		{
			dao[i]=min(dao[i+1],a[i+1]);
		}
		sort(zheng,zheng+n);
		sort(dao,dao+n);
		cout<< max(dao[n-1],zheng[n-1])<< endl;
	}
	else{
		sort(a,a+n);
	if(k==1)cout << a[0]<< endl;
	else if (k==3) cout << a[n-1]<< endl;
	}

}


#include <iostream>
#include <algorithm>
using namespace std;
int a[111111];
int main()
{
	int n,k;
	cin >> n >>k;
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	sort(a,a+n);
	if(k==1)cout << a[0]<< endl;
	else cout << a[n-1]<< endl;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
	ll arr[n],suf[n],pref[n];
	ll ans = 9999999999;
	ll ans1 = -1;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
		ans1 = max(ans1,arr[i]);
		ans = min(ans,arr[i]);
	}
	if(k==1){
		cout<<ans;
	}if(k>=3){
		cout<<ans1;
	}
	else {
		suf[n-1] = arr[n-1];
		for (int i = n-2; i>=0; i--)
		{
			suf[i] = min(arr[i],suf[i+1]);
		}
		ll ans2 = arr[0];
		ll ans3 = max(ans2,suf[1]);
		for (int i = 1; i <n-1 ; ++i)
		{
			ans2 = min(ans2,arr[i]);
			ans3 = max(ans3,max(suf[i+1],ans2));
		}
		cout<<ans3<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
	ll arr[n];
	ll ans = 9999999999;
	ll ans1 = -1;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
		ans1 = max(ans1,arr[i]);
		ans = min(ans,arr[i]);
	}
	if(k==1){
		cout<<ans;
	}
	else cout<<ans1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
	ll arr[n],suf[n],pref[n];
	ll ans = 9999999999;
	ll ans1 = -1;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
		ans1 = max(ans1,arr[i]);
		ans = min(ans,arr[i]);
	}
	if(k==1){
		cout<<ans;
	}else if(k>=3){
		cout<<ans1;
	}
	else {
		suf[n-1] = arr[n-1];
		for (int i = n-2; i>=0; i--)
		{
			suf[i] = min(arr[i],suf[i+1]);
		}
		ll ans2 = arr[0];
		ll ans3 = max(ans2,suf[1]);
		for (int i = 1; i <n-1 ; ++i)
		{
			ans2 = min(ans2,arr[i]);
			ans3 = max(ans3,max(suf[i+1],ans2));
		}
		cout<<ans3<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
	ll arr[n],suf[n],pref[n];
	ll ans = 9999999999;
	ll ans1 = -9999999999;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
		ans1 = max(ans1,arr[i]);
		ans = min(ans,arr[i]);
	}
	if(k==1){
		cout<<ans;
	}else if(k>=3){
		cout<<ans1;
	}
	else {
		suf[n-1] = arr[n-1];
		for (int i = n-2; i>=0; i--)
		{
			suf[i] = min(arr[i],suf[i+1]);
		}
		ll ans2 = arr[0];
		ll ans3 = max(ans2,suf[1]);
		for (int i = 1; i <n-1 ; ++i)
		{
			ans2 = min(ans2,arr[i]);
			ans3 = max(ans3,max(suf[i+1],ans2));
		}
		cout<<ans3<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int ej1(int a[], int n, int q)
{
    if (q == 1) return *min_element(a, a+n);

    return *max_element(a, a+n);
}

int main()
{
    int N, Q;
    cin >> N >> Q;

    int arr[N];
    for (int i = 0; i < N; ++i)
      cin >> arr[i];

    sort(arr,arr+N);

    cout << ej1(arr, N, Q);
}


#include <bits/stdc++.h>

int MAX =-999999999999, MIN=10000000000000;

using namespace std;

int main() {
	int n, q, a[100000+5];

	cin>>n>>q;

	for(int i=0; i < n ;i++) {
		cin>>a[i];
		MAX = max(a[i],MAX);
		MIN = min(a[i],MIN);
	}

	if (q == 1) cout<< MIN <<endl;
	else cout<< MAX <<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int ej1(int a[], int n, int q)
{
    if (q == 1) return *min_element(a, a+n);
    if (q == 2) return max(a[0], a[n-1]);
    return *max_element(a, a+n);
}

int main()
{
    int N, Q;
    cin >> N >> Q;

    int arr[N];
    for (int i = 0; i < N; ++i)
      cin >> arr[i];

    cout << ej1(arr, N, Q);
}


#include <bits/stdc++.h>

int MAX = INT_MIN, MIN=INT_MAX;

using namespace std;

int main() {
	int n, q, a[100000+5];

	cin>>n>>q;

	for(int i=0; i < n ;i++) {
		cin>>a[i];
		MAX = max(a[i],MAX);
		MIN = min(a[i],MIN);
	}

	if (q == 1) cout<< MIN <<endl;
	else if (q == 2) cout<< max(a[0], a[n-1]) <<endl;
	else cout<< MAX <<endl;
	return 0;
}


#include <bits/stdc++.h>

int MAX =-999999999999, MIN=10000000000000;

using namespace std;

int main() {
	int n, q, a[100000+5];

	cin>>n>>q;

	for(int i=0; i < n ;i++) {
		cin>>a[i];
		MAX = max(a[i],MAX);
		MIN = min(a[i],MIN);
	}

	if (q == 1) cout<< MIN <<endl;
	else if (q == 2) cout<< max(a[0], a[n-1]) <<endl;
	else cout<< MAX <<endl;
	return 0;
}