Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for {
		num := nextInt(sc)
		if num == 0 {
			break
		}

		score_list := []int{}
		for i := 0; i < num; i++ {
			score_list = append(score_list, nextInt(sc))
		}
		// 得点リストをソートした後、最低点と最高点を取り除く(3 ≤ n ≤ 100)
		sort.Sort(sort.IntSlice(score_list))
		score_list = score_list[1 : len(score_list)-1]
		// 得点リストの得点を合計し、スライスの個数で割って平均点を出す
		sum := 0
		for _, score := range score_list {
			sum += score
		}
		fmt.Println(sum / len(score_list))
	}
}

Python: while True:
    n = int(raw_input())
    if n == 0:
        break
    a = sorted([int(raw_input()) for _ in xrange(n)])
    print (sum(a)-a[0]-a[-1])/(len(a)-2)

Python: #!/usr/bin/python3

from math import floor

while True:
    n = eval(input())
    if n != 0:
        ls = []
        for i in range(n):
            m = eval(input())
            ls.append(m)
        ls.remove(max(ls))
        ls.remove(min(ls))
        print(floor(sum(ls)/len(ls)))
    else:
        break

Python: while True:
    n = int(input())
    if n == 0:
        break
    else:
        lst=[]
        for i in range(n):
            s = int(input())
            lst.append(s)
        print((sum(lst)-max(lst)-min(lst))//(n-2))

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Problems 1157
Problem A: ICPC 得点集計ソフトウェア
"""
while True:
    n = int(input())
    if  n == 0:
        break
    sum, s_min, s_max = 0, 1001, -1
    for i in range(n):
        score = int(input())
        s_min = min(s_min, score)
        s_max = max(s_max, score)
        sum += score
    print((sum-s_min-s_max)//(n-2))

Python: while True:
    n=int(input())
    x=[]
    if n==0:
        break
    else:
        for i in range(n):
            s=int(input())
            x.append(s)
        a=min(x)
        b=max(x)
        ave=(sum(x)-a-b)/(n-2)
        print(int(ave))

Python: while True:
    P = []
    n = int(input())
    if n == 0:
        exit()
    for i in range(n):
        P.append(int(input()))
    print(sum(sorted(P)[1:-1]) // (n-2))

Python: while True:
    N = int(input())
    if N == 0:
        break
    S = []
    for i in range(N):
        S.append(int(input()))
    print((sum(S) - max(S) - min(S))//(len(S)-2))

Python: str=readlines()
print(str)
print("aaa")

Python: while True:
    a=0
    ma=0
    mi=99999
    n = int(input())
    if n == 0:
        break
    else:
        for i in range(n):
            b=int(input())
            a=a+b
            if ma<b:
                ma=b
            if mi>b:
                mi=b
        answer=(a-ma-mi)//(n-2)
        print(answer)

Python: while True:
    n=int(input())
    if n==0:
        break
    else:
        a=[int(input()) for i in range(n)]
        x=max(a)
        y=min(a)
        a.remove(x)
        a.remove(y)
        ave = sum(a)//len(a)
        print(ave)

Python: while True:
    n = int(input())
    if n == 0:
        break
    else: 
        list=[]
        for i in range(n):
            list.append(int(input()))
            list.sort()
    print(sum(list[1:n-1])//(n-2))

Python: 
while True:
    n=int(input())
    if n==0: break
    a=[]
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Python: import sys

while True:
    n = int(sys.stdin.readline().rstrip())
    
    if n == 0:
        break
        
    scores = [int(sys.stdin.readline().rstrip()) for i in range(n)]
    result = (sum(scores) - (min(scores) + max(scores)) // n - 2)
    
    print(result)

Python: while True:
    N = int(input())
    if N == 0:
        break
    S = [ int(input()) for i in range(N)]
    S.sort()
    del S[len(S) - 1]
    del S[0]
    print(sum(S) // len(S))

Python: import math
while True:
    x = int(input())
    if x == 0:
        break
    a = list(int(input()) for i in range(x))
    
    a.sort()
    del a[0]
    del a[-1]
    
    b= sum(a)/len(a)
    print(math.floor(b))

Python: while True:
  n = int(input())
  if n == 0: break
  
  s=[int(input()) for i in range(n)]
  s.sort()
  point = (sum(s)-max(s)-min(s))//(len(s)-2)
  print(point)

Python: i=0
while True:
    n=int(input())
    list=[]
    for i in range(n):
        s=int(input())
        list.append((s))
        if i==n-1:
            list.sort()
            list.pop(n-1)
            list.pop(0)
            ave = sum(list)//len(list)
            print(ave)
    if n==0:
        break

Python: import math

def main():
    f = true
    r = []
    while f:
        n = int(input())
        if n == 0:
            break
        m = []
        for i in range(n):
            m.append(int(input()))
        r.append(math.floor((sum(m) - max(m) - min(m)/(n-2))))
    res = ''
    for j in r:
        res += str(j)
    print(j)
    
main()

Python: while True: #無限に繰り返す
    num = int(input()) #標準入力
    if num == 0:break #入力値が0だった場合繰り返しを強制終了する
    else: #0でなければ
        num_list = [] #空リスト作成
        for _ in range(num): #入力回繰り返す
            num_list.append(int(input())) #標準入力をし、リストに加える
        num_list.sort() #リストを小さい順に並べる
        num_list.pop(-1) #リストの最高点を削除する
        num_list.pop(0) #リストの最低点を削除する
        num = sum(num_list) #リストの値を合計する
        num1 = len(num_list) #リストの長さを取得する
        print(int(num / num1)) #リストの平均を出力する

Python: while True:
    n = int(input())
    if n == 0:
        exit()
    score = []
    for i in range(n):
        score.append(int(input()))
    print(sum(sorted(score)[1:-1]))

Python: while True:
    n=int(input())
    if n==0:
        break
    a=[]
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(n-2))

Python: while True:
    n = int(input())
    if not(n): break
    s = sum(sorted([int(input()) for i in range(n)])[1:-1])
    print(s//(n-2))

Python: while True:
    n=int(input())
    if n==0:
        break
    a=[]
    for i in range(n):
        a.append(int(input()))
    print((sum(a)-max(a)-min(a))//(len(a)-2))

Python: while 1:
    n=int(input())
    if n==0:break
    a=[int(input()) for _ in range(n)]
    print((sum(a)-max(a)-min(a))//(n-2))

Python: r = []
while True:
    n = int(input())
    if n == 0:
        break
    p = []
    for i in range(n):
        p.append(int(input()))
    p.remove(min(p))
    p.remove(max(p))
    r.append(sum(p)//len(p))
[print(i) for i in r]

Python: while True:
    n = int(input())
    if n == 0:
        break

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

    s.sort()
    #print(s)
    ans = sum(s[1:n - 1]) // (n - 2)
    print(ans)

Python: while True:
  n = int(input())
  if n == 0:
    break
  score =[]
  for i in range(n):
    score.append(int(input()))
  print((sum(score)-min(score)-max(score))//(n-2))

Python: while True:
    try:
        n = int(input())
        MIN = 1000
        MAX = 0
        points = 0
        for i in range(n):
            p = int(input())
            if MIN > p:
                MIN = p
            if MAX < p:
                MAX = p
            points += p
        print((points - MIN - MAX) // (n - 2))
    except:
        break

Python: #!/usr/bin/env python3
#ICPC A

while 1:
    n = int(input())
    if n == 0:
        break
    s = [int(input()) for _ in range(n)]
    s.sort()
    ans = sum(s[1:n-1])/(n-2)
    print(int(ans))

Python: # coding: utf-8
def q0():
    while True:
        data=[]
        n=int(input())
        if n==0:
            return
        for i in range(n):
            data.append(int(input()))
        print((sum(data)-max(data)-min(data))//(n-2))

def q1():
    while True:
        n,r=map(int,input().split())
        if n==0:
            return
        deck=[n-i for i in range(n)]
        for i in range(r):
            p,c=map(int,input().split())
            deck=deck[p-1:p-1+c]+deck[0:p-1]+deck[p-1+c:]
        print(deck[0])


question=[q0,q1]

question[0]()