CodeEff/ECCO huggingface dataset:
# Original solution
import sys
sys.setrecursionlimit(10**9)

def mi(): return list(map(int,input().split()))
def ii(): return int(eval(input()))
def isp(): return input().split()
def deb(text): print(("-------\n{}\n-------".format(text)))

INF=10**20
def main():
    N = ii()
    A = list(mi())

    A.sort()
    if A[0] == 1:
        print((1))
        exit()
    
    ini = A[0]
    while len(A) > 1:
        x = A[0]
        B = set([x])
        for a in A:
            b = a%x
            if b > 0:
                B.add(b)

        A = list(B)
        #print(A)

    if len(A) > 0:
        print((A[0]))
    else:
        print(ini)
            

            
        



if __name__ == "__main__":
    main()

# Optimized solution
import sys
sys.setrecursionlimit(10**9)

def mi(): return list(map(int,input().split()))
def ii(): return int(eval(input()))
def isp(): return input().split()
def deb(text): print(("-------\n{}\n-------".format(text)))

INF=10**20
def main():
    N = ii()
    A = list(mi())

    A.sort()
    if A[0] == 1:
        print((1))
        exit()
    
    ini = A[0]
    while len(A) > 1:
        x = A[0]
        B = set([x])
        for a in A:
            b = a%x
            if b > 0:
                B.add(b)

        A = list(B)
        A.sort()

    if len(A) > 0:
        print((A[0]))
    else:
        print(ini)
            

            
        



if __name__ == "__main__":
    main()
# Original solution
N,K,X,Y=int(eval(input())),int(eval(input())),int(eval(input())),int(eval(input()))
print((K*X+(N-K)*Y if N > K else N*X))

# Optimized solution
n,k,x,y=[int(eval(input())) for _ in range(4)];print(([n*x,k*x+(n-k)*y][n-k>0]))
# Original solution
#coding: utf-8
N, K, X, Y = [int(eval(input())) for _ in range(4)]
print((X * K + (N-K) * Y if N >= K else X * N))

# Optimized solution
#coding: utf-8
N, K, X, Y = [int(eval(input())) for _ in range(4)]
print((X * min(K,N) + max((N-K), 0) * Y))
# Original solution

n = int(eval(input()))
k = int(eval(input()))
x = int(eval(input()))
y = int(eval(input()))
if n <= k:
  print((n*x))
else:
  print((k*x + (n-k)*y))

# Optimized solution
n,k,x,y = [int(eval(input())) for i in range(4)]
cost = (min(n,k)*x+max(0,n-k)*y)
print(cost)
# Original solution
N = int(eval(input()))
K = int(eval(input()))
X = int(eval(input()))
Y = int(eval(input()))

if N-K > 0:
    print((X*K+(N-K)*Y))
else:
    print((X*N))


# Optimized solution
n, k, x, y = (int(eval(input())) for i in range(4))

print((n*x-(x-y)*max((n-k), 0)))
# Original solution
N,K,X,Y = [int(eval(input())) for _ in range(4)]
cnt = 0
for i in range(N):
    if i<K:
        cnt += X
    else:
        cnt += Y
print(cnt)

# Optimized solution
n,k,x,y = [int(eval(input())) for _ in range(4)]
if n>k:
    print((k*x+(n-k)*y))
else:
    print((n*x))
# Original solution
n = int(eval(input()))
k = int(eval(input()))
x = int(eval(input()))
y = int(eval(input()))

ans = 0

for i in range(n):
    if i + 1 <= k:
        ans += x
    else:
        ans += y
        
print(ans)
    

# Optimized solution
n, k, x, y = [int(eval(input())) for i in range(4)]

print((k*x + (n-k)*y if n >= k else n*x))
# Original solution
n, k, x, y = [int(eval(input())) for i in range(4)]
sum = 0

for t in range(1, n+1):
    if t <= k:
        sum += x
    else:
        sum += y

print(sum)


# Optimized solution
n = int(eval(input()))
k = int(eval(input()))
x = int(eval(input()))
y = int(eval(input()))

if n <= k:
    ans = n * x
else:
    ans = k * x + (n-k) * y

print(ans)
# Original solution
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list([int(x)-1 for x in stdin.readline().split()])
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, k, x, y = IR(4)
    ans = 0
    for i in range(n):
        if i >= k:
            ans += y
        else:
            ans += x
    print(ans)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


# Optimized solution
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list([int(x)-1 for x in stdin.readline().split()])
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, k, x, y = II(),II(),II(),II()
    ans = 0
    for i in range(n):
        if i >= k:
            ans += y
        else:
            ans += x
    print(ans)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()
# Original solution
a = [int(eval(input())) for i in range(4)]
if a[0] <= a[1]:
  print((a[0]*a[2]))
else:
  print((a[1]*a[2] + (a[0]-a[1])*a[3]))

# Optimized solution
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))

if a > b:
  print((b*c+(a-b)*d))
else:
  print((a*c))
# Original solution
n=int(eval(input()))
k=int(eval(input()))
x=int(eval(input()))
y=int(eval(input()))

if k<n:
    print((x*k+y*(n-k)))
else:
    print((x*n))

# Optimized solution
n,k,x,y=[int(eval(input())) for _ in range(4)]
print((x*min(k,n)+y*max(n-k,0)))
# Original solution
l = [int(eval(input())) for _ in range(4)]
if l[1] >= l[0]:
  print((l[0]*l[2]))
else:
  print((l[1]*l[2] + (l[0]-l[1])*l[3]))

# Optimized solution
n,k,x,y = (int(eval(input())) for _ in range(4))
print((min(n,k)*x + y*max(n-k,0)))
# Original solution
N, K, X, Y = (int(eval(input())) for i in range(4))
print((K * X + (N - K) * Y if N > K else N * X))

# Optimized solution
N = int(eval(input()))
K = int(eval(input()))
X = int(eval(input()))
Y = int(eval(input()))
if N > K:
	print((K * X + (N - K) * Y))
else:
	print((N * X))
# Original solution
N = int(eval(input()))
K = int(eval(input()))
X = int(eval(input()))
Y = int(eval(input()))
P = 0
for i in range(1,N+1):
  if i <= K:
    P = P + X
  else:
    P = P + Y
print(P)

# Optimized solution
N, K, X, Y = (int(eval(input())) for i in range(4))
P = 0
for i in range(1,N+1):
  if i <= K:
    P = P + X
  else:
    P = P + Y
print(P)
# Original solution
total_stay = int(eval(input()))
normal_stay = int(eval(input()))
normal_cost = int(eval(input()))
discounted_cost = int(eval(input()))
if total_stay <= normal_stay:
  total_cost = total_stay * normal_cost
else:
  total_cost = normal_stay * normal_cost + (total_stay - normal_stay) * discounted_cost
print(total_cost)

# Optimized solution
N = int(eval(input()))
K = int(eval(input()))
X = int(eval(input()))
Y = int(eval(input()))
if N <= K:
  print((N * X))
else:
  print((K * X + (N - K) * Y))
# Original solution
N = int(eval(input()))
K = int(eval(input()))
X = int(eval(input()))
Y = int(eval(input()))

if N <= K:
    print((N*X))
else:
    print((K*X + (N-K)*Y))


# Optimized solution
N = int(eval(input()))
K = int(eval(input()))
X = int(eval(input()))
Y = int(eval(input()))

if N <= K:
    print((N*X))
else:
    print((K*X+Y*(N-K)))
# Original solution
N,K,X,Y=[int(eval(input())) for i in range(4)]
print((N*X-(X-Y)*max(0,N-K)))

# Optimized solution
N,K,X,Y=[int(eval(input())) for i in range(4)]
print((min(N,K)*X+max(0,N-K)*Y))
# Original solution
N = int(eval(input()))
K = int(eval(input()))
X = int(eval(input()))
Y = int(eval(input()))
if N<=K:
    c = X*N
else:
    c = X*K+Y*(N-K)
print(c)

# Optimized solution
N = int(eval(input()))
K = int(eval(input()))
X = int(eval(input()))
Y = int(eval(input()))
if N<=K:
    ans = X*N
else:
    ans = X*K
    ans += Y*(N-K)
print(ans)
# Original solution
n,k,x,y=eval('int(input()),'*4);print((n*x-(x-y)*max(n-k,0)))

# Optimized solution
n,k,x,y=list(map(int,open(0)));print((n*x-(x-y)*max(n-k,0)))
# Original solution
n=int(eval(input()))
k=int(eval(input()))
x=int(eval(input()))
y=int(eval(input()))
yen = 0
for i in range(n):
  if i < k:
    yen += x
  else:
    yen += y
print(yen)

# Optimized solution
n=int(eval(input()))
k=int(eval(input()))
x=int(eval(input()))
y=int(eval(input()))

if n <= k:
  ans = n*x
else:
  ans = k*x + (n-k)*y
print(ans)
# Original solution
# -*- coding: utf-8 -*-
# template: v1.2

import io
import sys
import math

def solve(n,k,x,y):
    # implement process
    higher = n-k
    if higher < 1:
        return n*x
    else:
        return k*x + higher*y



def main():
    # input
    n,k,x,y = list(map(int,sys.stdin.read().split()))
    
    # process
    ans = str( solve(n,k,x,y) )
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
2
3
10000
9000
"""
_EXPECTED = """\
20000
"""

def logd(str):
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

# Optimized solution
import sys
n,k,x,y = list(map(int,sys.stdin.read().split()))
high=n-k
ans=0
if high > 0:
  ans=x*k+high*y
else:
  ans=n*x
print(ans)
# Original solution
a = [int(eval(input())) for i in range(4)]
if a[0] <= a[1]:
  print((a[0] * a[2]))
else:
  print((a[1] * a[2] + (a[0] - a[1]) * a[3]))

# Optimized solution
n,k,x,y= [int(eval(input())) for i in range(4)]
print((n * x + (y-x) * max(n-k,0)))
# Original solution
n = int(eval(input()))
k = int(eval(input()))
x = int(eval(input()))
y = int(eval(input()))
price = 0
for i in range(1, n + 1):
  price += x if i <= k else y
print(price)
    

# Optimized solution
N = int(eval(input()))
K = int(eval(input()))
X = int(eval(input()))
Y = int(eval(input()))

val = 0
for i in range(N):
  val += X if i < K else Y
print(val)
# Original solution
N = int(eval(input()))
K = int(eval(input()))
X = int(eval(input()))
Y = int(eval(input()))

cnt = 0
for i in range(N):
  if(i < K):
    cnt += X
  else:
    cnt += Y
print(cnt)

# Optimized solution
N = int(eval(input()))
K = int(eval(input()))
X = int(eval(input()))
Y = int(eval(input()))
print((min(K, N)*X + max(0,(N-K))*Y))
# Original solution
n = int(eval(input()))
k = int(eval(input()))
x = int(eval(input()))
y = int(eval(input()))

price = n*x if (n < k) else (k*x + (n-k)*y)
print(price)

# Optimized solution
n = int(eval(input()))
k = int(eval(input()))
x = int(eval(input()))
y = int(eval(input()))
v = n*x if (n <= k) else k*x + (n-k)*y
print(v)
# Original solution
a, b, c, d = [int(eval(input())) for i in range(4)]
if a-b > 0:
    print((b*c + (a-b)*d))
else:
    print((a*c))

# Optimized solution
n,k,x,y=(int(eval(input())) for i in range(4))
print((n*x-(x-y)*max(n-k, 0)))
# Original solution
import itertools
from copy import deepcopy

def turnOverRow(now_state,combs,c):
    for i in combs:
        for j in range(c):
            now_state[i][j]=0 if now_state[i][j]==1 else 1

def turnOverCol(now_state,r,c):
    h=r/2
    for i in range(c):
        cnt=0
        for j in range(r):
            if now_state[j][i]==1:
                cnt+=1
        if cnt>h:
            for j in range(r):
                now_state[j][i]=1 if now_state[j][i]==0 else 0

def countMax(now_state,r):
    return sum(sum(now_state[i]) for i in range(r))

while True:
    r,c=list(map(int,input().split()))
    if r==c==0:break
    init_state=[list(map(int,input().split())) for i in range(r)]
    now_state=deepcopy(init_state)
    ans=10000000000
    for i in range(r+1):
        for combs in itertools.combinations(list(range(r)),i):
            turnOverRow(now_state,combs,c)
            turnOverCol(now_state,r,c)
            ans=min(ans,countMax(now_state,r))
            now_state=deepcopy(init_state) #initialization
    print(r*c-ans)

# Optimized solution
while True:
    r,c=list(map(int,input().split()))
    if r==c==0:break
    state=[input().split() for i in range(r)]
    state=list(map(list,list(zip(*state))))
    new_state=[int("".join(ls),2) for ls in state]
    ans=0
    h=r/2
    for i in range(pow(2,r)):
        cnt=0
        for j in new_state:
            b=format(i^j,"b")
            n=b.count("1")
            cnt+=n if n>h else r-n
        ans=max(ans,cnt)
    print(ans)
# Original solution
while True:
    r,c=list(map(int,input().split()))
    if r==c==0:break
    state=[input().split() for i in range(r)]
    state=list(map(list,list(zip(*state))))
    new_state=[int("".join(ls),2) for ls in state]
    ans=0
    h=r/2
    for i in range(pow(2,r)):
        cnt=0
        for j in new_state:
            b=format(i^j,"b")
            n=b.count("1")
            cnt+=n if n>h else r-n
        ans=max(ans,cnt)
    print(ans)

# Optimized solution
while True:
    r,c=list(map(int,input().split()))
    if r==c==0:break
    state=[input().split() for i in range(r)]
    state=list(map(list,list(zip(*state))))
    new_state=[int("".join(ls),2) for ls in state]
    ans=0
    h=r/2
    for i in range(pow(2,r)):
        cnt=0
        for j in new_state:
            n=bin(i^j).count("1")
            cnt+=n if n>h else r-n
        ans=max(ans,cnt)
    print(ans)
# Original solution
for e in iter(input,'0 0'):
 r,_=list(map(int,e.split()))
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=max(c,r-c)
  a=max(a,b)
 print(a)


# Optimized solution
for e in iter(input,'0 0'):
 r,_=list(map(int,e.split()))
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=[r-c,c][c>r//2]
  if b>a:a=b
 print(a)
# Original solution
for e in iter(input,'0 0'):
 r,_=list(map(int,e.split()))
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=[r-c,c][c>r//2]
  if b>a:a=b
 print(a)


# Optimized solution
for e in iter(input,'0 0'):
 r,_=list(map(int,e.split()))
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=c if c>r//2else r-c
  a=max(a,b)
 print(a)
# Original solution
import sys
e = sys.stdin.readlines()
while 1:
 r=int(e[0].split()[0])
 if r<1:break
 d=[int(''.join(x),2)for x in zip(*[x.split() for x in e[1:r+1]])]
 a=[]
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=c if c>r//2 else r-c
  a+=[b]
 print((max(a)))
 del e[:r+1]


# Optimized solution
for e in iter(input,'0 0'):
 r=int(e.split()[0])
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 b=1<<r
 f=[1]*b
 for m in range(b):
  if f[m]:
   f[~m]=0
   t=0
   for s in d:
    c=bin(m^s).count('1')
    t+=c if c>r//2 else r-c
   if a<t:a=t
 print(a)
# Original solution
for e in iter(input,'0 0'):
 r=int(e.split()[0])
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 b=1<<r
 f=[1]*b
 for m in range(b):
  if f[m]:
   f[~m]=0
   t=0
   for s in d:
    c=bin(m^s).count('1')
    t+=c if c>r//2 else r-c
   if a<t:a=t
 print(a)


# Optimized solution
for e in iter(input,'0 0'):
 r=int(e.split()[0])
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 for m in range(1<<~-r):
  t=0
  for s in d:
   c=bin(m^s).count('1')
   t+=c if c>r//2 else r-c
  if a<t:a=t
 print(a)
# Original solution
for e in iter(input,'0 0'):
 r=int(e.split()[0])
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 for m in range(1<<~-r):
  t=0
  for s in d:
   c=bin(m^s).count('1')
   t+=c if c>r//2 else r-c
  if a<t:a=t
 print(a)


# Optimized solution
def v():
 for e in iter(input,'0 0'):
  r=int(e.split()[0])
  d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
  a=0
  for m in range(1<<~-r):
   t=0
   for s in d:
    c=bin(m^s).count('1')
    t+=c if c>r//2 else r-c
   if a<t:a=t
  print(a)
if'__main__'==__name__:v()
# Original solution
def v():
 for e in iter(input,'0 0'):
  r=int(e.split()[0])
  d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
  a=0
  for m in range(1<<~-r):
   t=0
   for s in d:
    c=sum(map(int,bin(m^s)[2:]))
    t+=c if c>r//2 else r-c
   if a<t:a=t
  print(a)
if'__main__'==__name__:v()


# Optimized solution
def v():
 for e in iter(input,'0 0'):
  r=int(e.split()[0])
  d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
  a=0
  for m in range(1<<~-r):
   t=0
   for s in d:
    c=bin(m^s).count('1')
    t+=max(c,r-c)
   if a<t:a=t
  print(a)
if'__main__'==__name__:v()
# Original solution
def hantei(field,r,c):
    count=0
    for i in range(c):
        countc=0
        for j in range(r):
            countc=countc+field[j][i]
        count=max(countc,r-countc)+count
    return count
    
def turnr(field,rn,r,c):
    if rn==r:
        return hantei(field,r,c)
    field1=field
    field2=field
    field2[rn]=[not x for x in field[rn]]
    return max(turnr(field1,rn+1,r,c),turnr(field2,rn+1,r,c))

while(1):
    [r,c]=[int(x) for x in input().split()]
    if r==0:
        break
    else:
        field=[]
        for i in range(r):
            field.append([int(x) for x in input().split()])
        print(turnr(field,0,r,c))

# Optimized solution

def hanteib(bfield,r,c):
    count=0
    for b in bfield:
        ccount=bin(b).count("1")
        count=count+max(ccount,r-ccount)
    return count

def turnrb(bfield,rn,r,c):
    if rn==r:
        return hanteib(bfield,r,c)
    bfield1=bfield
    bfield2=[b ^ 2**rn for b in bfield]
    return max(turnrb(bfield1,rn+1,r,c),turnrb(bfield2,rn+1,r,c))

while(1):
    [r,c]=[int(x) for x in input().split()]
    if r==0:
        break
    else:
        field=[]
        bfield=[]
        for i in range(r):
            field.append([int(x) for x in input().split()])
        for j in range(c):
            bb=0
            for i in range(r):
                bb=bb+2**i*field[i][j]
            bfield.append(bb)
        print(turnrb(bfield,0,r,c))
# Original solution
def main():
  while True:
    r,c = list(map(int,input().split()))
    if not r and not c:
      break
    lst = []
    for i in range(r):
      lst.append(list(map(int,input().split())))
    def dfs(l,n):
      if n == r:
        ans = 0
        for i in range(c):
          count = 0
          for j in range(r):
            if l[j][i]:
              count += 1
          ans += max(count, r - count)
        return ans
      else:
        return max(dfs(l + [[0 if i else 1 for i in lst[n]]],n + 1),
                   dfs(l + [[1 if i else 0 for i in lst[n]]],n + 1))
    print((dfs([],0)))

main()


# Optimized solution
while True:
  r,c = list(map(int,input().split()))
  if not r:
    break
  lst = [list(map(int,input().split())) for i in range(r)]
  dic = [0 for i in range(2 ** r)]
  for i in range(c):
    num = 0
    for j in range(r):
      num *= 2
      num += lst[j][i]
    dic[num] += 1
  ans = 0
  for i in range(2 ** r):
    ret = 0
    for j in range(2 ** r):
      num = (i ^ j)
      cnt = 0
      for k in range(r):
        cnt += num % 2
        num //= 2
      ret += max(cnt, r - cnt) * dic[j]
    ans = max(ans, ret)
  print(ans)
# Original solution
while True:
  r,c = list(map(int,input().split()))
  if not r:
    break
  lst = [list(map(int,input().split())) for i in range(r)]
  dic = [0 for i in range(2 ** r)]
  for i in range(c):
    num = 0
    for j in range(r):
      num *= 2
      num += lst[j][i]
    dic[num] += 1
  ans = 0
  for i in range(2 ** r):
    ret = 0
    for j in range(2 ** r):
      num = (i ^ j)
      cnt = 0
      for k in range(r):
        cnt += num % 2
        num //= 2
      ret += max(cnt, r - cnt) * dic[j]
    ans = max(ans, ret)
  print(ans)



# Optimized solution
def f():
  while True:
    r,c = list(map(int,input().split()))
    if not r:
      break
    lst = [list(map(int,input().split())) for i in range(r)]
    dic = [0 for i in range(2 ** r)]
    for i in range(c):
      num = 0
      for j in range(r):
        num *= 2
        num += lst[j][i]
      dic[num] += 1
    ans = 0
    for i in range(2 ** r):
      ret = 0
      for j in range(2 ** r):
        num = (i ^ j)
        cnt = 0
        for k in range(r):
          cnt += num % 2
          num //= 2
        ret += max(cnt, r - cnt) * dic[j]
      ans = max(ans, ret)
    print(ans)
f()
# Original solution
import itertools
while 1:
	R,C = list(map(int,input().split()))
	if R == 0: break
	A = [list(map(int,input().split())) for i in range(R)]
	ans = 0
	for n in range(1,R+1):
		for flip in itertools.combinations(list(range(R)),n):
			cur = 0
			for ci in range(C):
				s = sum((A[ri][ci] if ri not in flip else 1 - A[ri][ci]) for ri in range(R))
				cur += max(s,R-s)
			ans = max(ans,cur)
	print(ans)

# Optimized solution
def solve(A,flip):
	res = 0
	if len(flip) != H:
		res = max(res,solve(A,flip+[1]),solve(A,flip+[0]))
	else:
		B = [A[i][:] for i in range(H)]
		for h in range(H):
			if flip[h]:
				B[h] = [1-val for val in B[h]]
		for w in range(W):
			good = sum(1-B[h][w] for h in range(H))
			res += max(good,H-good)
	return res
	
while 1:
	H,W = list(map(int,input().split()))
	if H == W == 0:
		break
	A = [list(map(int,input().split())) for h in range(H)]
	print(solve(A,[]))
# Original solution
while 1:
    r, c = list(map(int, input().split()))
    if r == 0: break
    old = [None for i in range(r)]
    new = [[True]*c for i in range(r)]
    for i in range(r):
        old[i] = "".join(map(str, input().split()))
    ans = 0
    n = 1<<r
    for i in range(n):
        for j in range(r):
            if i & (1<<j):
                for k in range(c):
                    new[j][k] = bool(int(old[j][k])) ^ True
            else:
                for k in range(c):
                    new[j][k] = bool(int(old[j][k]))
        ret = 0
        for j in range(c):
            cnt = 0
            for k in range(r):
                if not new[k][j]: cnt+=1
            ret += cnt if cnt > r/2 else r-cnt
        ans = max(ans, ret)
    print(ans)

# Optimized solution
while 1:
    r, c = list(map(int, input().split()))
    if r == 0: break
    old = [input().split() for i in range(r)]
    old = list(map(list, list(zip(*old))))
    new = [int("".join(lst),2) for lst in old]
    ans = 0
    for i in range(1<<r):
        ret = 0
        for j in new:
            cnt = bin(i^j).count('1')
            ret += cnt if cnt > r/2 else r-cnt
        ans = max(ans, ret)
    print(ans)