def solution():
    _range, _int, _tuple, _max = range, int, tuple, max
    from sys import stdout, stdin
    _input, _print = stdin.readline, stdout.write
    for _ in _range(_int(_input())):
        n = _int(_input())
        arr = {_tuple(_int(i) for i in _input().split()) for j in _range(n)}
        row, column = _max(arr, key=lambda x: x[0]), _max(arr, key=lambda x: x[1])
        row, column = row[0]+1, column[1]+1
        dp = [[0]*column for i in _range(row)]
        ans = [[0]*column for i in _range(row)]
        for i in _range(row):
            for j in _range(column):
                if (i,j) in arr:
                    adder = 1
                else:
                    adder = 0
                if i == 0 and j == 0:
                    dp[i][j] = adder
                elif i == 0:
                    dp[i][j] = dp[i][j-1]+adder
                    ans[i][j] = 1
                elif j == 0:
                    dp[i][j] = dp[i-1][j]+adder
                    ans[i][j] = 0
                elif dp[i-1][j] > dp[i][j-1]:
                    ans[i][j] = 0
                    dp[i][j] = dp[i-1][j]+adder
                else:
                    ans[i][j] = 1
                    dp[i][j] = dp[i][j-1]+adder
        if dp[row-1][column-1] == n:
            _print("YES\n")
            i, j = row-1, column-1
            ret_str = ''
            while i != 0 or j != 0:
                if ans[i][j] == 1:
                    ret_str = "U" + ret_str
                    j -= 1
                else:
                    ret_str = "R" + ret_str
                    i -= 1
            _print(ret_str+"\n")
        else:
            _print("NO\n")
solution()


for _ in range(int(input())):
    n = int(input())
    arr = {tuple(int(i) for i in input().split()) for j in range(n)}
    row, column = max(arr, key=lambda x: x[0]), max(arr, key=lambda x: x[1])
    row, column = row[0]+1, column[1]+1
    dp = [[0]*column for i in range(row)]
    ans = [[0]*column for i in range(row)]
    for i in range(row):
        for j in range(column):
            if (i,j) in arr:
                adder = 1
            else:
                adder = 0
            if i == 0 and j == 0:
                dp[i][j] = adder
            elif i == 0:
                dp[i][j] = dp[i][j-1]+adder
                ans[i][j] = 1
            elif j == 0:
                dp[i][j] = dp[i-1][j]+adder
                ans[i][j] = 0
            elif dp[i-1][j] > dp[i][j-1]:
                ans[i][j] = 0
                dp[i][j] = dp[i-1][j]+adder
            else:
                ans[i][j] = 1
                dp[i][j] = dp[i][j-1]+adder
    if dp[row-1][column-1] == n:
        print("YES")
        i, j = row-1, column-1
        ret_str = ''
        while i != 0 or j != 0:
            if ans[i][j] == 1:
                ret_str = "U" + ret_str
                j -= 1
            else:
                ret_str = "R" + ret_str
                i -= 1
        print(ret_str)
    else:
        print("NO")


for _ in range(int(input())):
   n=int(input())
   k=[]
   for i in range(n):
      k.append(list(map(int,input().split())))
   k.sort()
   flag=0
   m=[]
   s=""
   if (k[0][0]-0)>0:
     s+='R'*(k[0][0]-0)
   if (k[0][0]-0)>0:
     s+='U'*(k[0][1]-0)
   if (k[0][0]-0)+(k[0][0]-0)>=1:
       m.append(s)
   for i in range(n-1):
        s=""
        dif1=k[i+1][0]-k[i][0]
        if dif1>0:
         s+='R'*dif1
        dif2=k[i+1][1]-k[i][1]
        if dif2>0:
         s+='U'*dif2
        if dif1+dif2<1:
           flag=1
           break
        else:
           m.append(s)
   if flag==1:
      print("NO")
   else:
      print("YES")
      for i in m:
       print(i,end="")
      print(end="\n")


for _ in range(int(input())):
   n=int(input())
   k=[]
   for i in range(n):
      k.append(list(map(int,input().split())))
   k.sort()
   flag=0
   m=[]
   s=""
   s+='R'*(k[0][0]-0)
   s+='U'*(k[0][1]-0)
   m.append(s)
   for i in range(n-1):
        s=""
        dif1=k[i+1][0]-k[i][0]
        s+='R'*dif1
        dif2=k[i+1][1]-k[i][1]
        s+='U'*dif2
        if dif1+dif2<1:
           flag=1
           break
        else:
           m.append(s)
   if flag==1:
      print("NO")
   else:
      print("YES")
      for i in m:
       print(i,end="")
      print(end="\n")


for _ in range(int(input())):
   n=int(input())
   k=[]
   for i in range(n):
      k.append(list(map(int,input().split())))
   k.sort()
   flag=0
   m=[]
   s=""
   s+='R'*(k[0][0]-0)
   s+='U'*(k[0][1]-0)
   m.append(s)
   for i in range(n-1):
        s=""
        dif1=k[i+1][0]-k[i][0]
        s+='R'*dif1
        dif2=k[i+1][1]-k[i][1]
        s+='U'*dif2
        if dif1<0 or dif2<0:
           flag=1
           break
        else:
           m.append(s)
   if flag==1:
      print("NO")
   else:
      print("YES")
      for i in m:
       print(i,end="")
      print(end="\n")


#Codeforces - Collecting Coins

t = int(input())

while t!=0:
    a,b,c,n = map(int, input().split())
    arr = []
    arr.append(a)
    arr.append(b)
    arr.append(c)
    arr.sort()
    x = arr[2] - arr[1]
    y = arr[2] - arr[0]
    result = "NO"
    if (n >= x + y):
        if (n - x - y)%3 == 0:
            result ='YES'
    print(result)
    t-=1


#Codeforces - Collecting Packages

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def __lt__(self, other):
        if self.x < other.x:
            return True
        elif self.x == other.x:
            return self.y <= other.y
        return False

t = int(input())

while t!=0:
    n = int(input())
    arrCor = []
    for i in range(n):
        x,y = map(int, input().split())
        arrCor.append(Point(x, y))
    arrCor.sort()
    result = ''
    curX = 0
    curY = 0
    for i in range(n):
        if curY > arrCor[i].y:
            result='NO'
            break
        if curX < arrCor[i].x:
            for j in range(curX,arrCor[i].x,1):
                result+='R'
            curX = arrCor[i].x
        if curY < arrCor[i].y:
            for j in range(curY,arrCor[i].y,1):
                result+='U'
            curY = arrCor[i].y
    if result!='NO':
        print('YES')
        print(result)
    else:
        print(result)
    t-=1


for t in range(int(input())):
    n = int(input())
    l  =[]
    for i in range(n):
        a = list(map(int,input().split()))
        l.append(a)
    l.sort()
    b = [0 , 0 ]
    flag = 'YES'
    s = ''
    for i in l :
        if i[0] - b[0] >= 0 and i[1] - b[1] >= 0 :
            s += 'R' * (i[0] - b[0]) + 'U' * (i[1] - b[1])
            b = i

        else:
            flag = 'NO'

    if flag == 'YES':
        print('YES')
        print(s)

    else:
        print(flag)


for t in range(int(input())):
    n = int(input())
    l = []
    for i in range(n):
        a = list(map(int,input().split()))
        l.append(a)
    l.sort()
    #print(l)
    a = [0 , 0]
    flag = 'YES'
    s = ''
    for i in l :
        if i[0] - a[0] >= 0 and i[1] - a[1] >= 0 :
            s += 'R' * (i[0] - a[0]) + 'U' * (i[1] - a[1])
            a = i

        else:
            flag = 'NO'

    if flag == 'YES':
        print('YES')
        print(s)
    else:
        print(flag)


t=int(input())
for i in range(t):
	x=[]
	n=int(input())
	for i in range(n):
		a,b=map(int,input().split())
		x.append([a,b])
	x.sort(key=lambda x:x[0])
	arr=[]
	for i in range(1010):
		arr.append([])
	for i in x:
		arr[i[1]].append(i[0])
	for i in range(1010):
		arr[i].sort()

	ans=''
	flag=1
	last_y=0
	last_x=0
	y=0
	for i in arr:
		if(len(i)!=0):
			for j in i:
				k=(j-last_x)
				if(k<0):
					flag=0
					break
				last_x=j
				ans+='R'*k
				k=(y-last_y)
				if(k<0):
					flag=0
					break
				ans+='U'*k
				last_y=y
			if(flag==0):
				break
		y+=1

	if(flag==0):
		print("NO")
	else:
		print("YES")
		print(ans)


t=int(input())
for i in range(t):
	x=[]
	n=int(input())
	for i in range(n):
		a,b=map(int,input().split())
		x.append([a,b])
	x.sort(key=lambda x:x[0])
	arr=[]
	for i in range(1000):
		arr.append([])
	for i in x:
		arr[i[1]].append(i[0])
	for i in range(1000):
		arr[i].sort()

	ans=''
	flag=1
	last_y=0
	last_x=0
	y=0
	for i in arr:
		if(len(i)!=0):
			for j in i:
				k=(j-last_x)
				if(k<0):
					flag=0
					break
				last_x=j
				ans+='R'*k
				k=(y-last_y)
				if(k<0):
					flag=0
					break
				ans+='U'*k
				last_y=y
			if(flag==0):
				break
		y+=1

	if(flag==0):
		print("NO")
	else:
		print("YES")
		print(ans)


from operator import itemgetter

t = int(input())

while t > 0:
    n = int(input())
    points = []
    for i in range(n):
        points.append([int(i) for i in input().split()])
    points = sorted(points, key=itemgetter(0, 1))

    x = y = 0
    flag = 1
    ans = ""
    for p in points:
        if p[1] < y:
            flag = 0
            break

        ans += "R" * (p[0] - x)
        ans += "U" * (p[1] - y)
        x = p[0]
        y = p[1]

    if flag:
        print("YES")
        print(ans)
    else:
        print("NO")
    t -= 1


from operator import itemgetter

t = int(input())

while t > 0:
    n = int(input())
    points = []
    for i in range(n):
        points.append([int(i) for i in input().split()])
    points = sorted(points, key=itemgetter(0, 1))

    x = y = 0
    flag = 1
    ans = ""
    for p in points:
        if p[1] < y:
            print(p, y)
            flag = 0
            break

        ans += "R" * (p[0] - x)
        ans += "U" * (p[1] - y)
        x = p[0]
        y = p[1]

    if flag:
        print("YES")
        print(ans)
    else:
        print("NO")
    t -= 1


t = int(input())

def check(pos):
    for f in range(1, len(pos)):
        if pos[f][1] < pos[f-1][1]:
            return 'NO'

    i = [0, 0]
    ans = ''

    for f in pos:
        while i[0] < f[0]:
            i[0] += 1
            ans = ans + 'R'
        while i[1] < f[1]:
            i[1] += 1
            ans = ans + 'U'

    print('YES')
    return ans

for _ in range(t):
    n = int(input())
    pos = []
    for _ in range(n):
        pos.append(list(int(x) for x in input().split()))

    pos = sorted(pos)

    print(check(pos))


t = int(input())

def check(pos):
    for f in range(1, pos.len):
        if pos[f][1] < pos[f-1][1]:
            return 'NO'

    i = [0, 0]
    ans = ''

    for f in pos:
        while i[0] < f[0]:
            i[0] += 1
            ans = ans + 'R'
        while i[1] < f[1]:
            i[1] += 1
            ans = ans + 'U'

    print('YES')
    return ans

for _ in range(t):
    n = int(input())
    pos = []
    for _ in range(n):
        pos.append(list(int(x) for x in input().split()))

    pos = sorted(pos)

    print(check(pos))


for i in range(int(input())):
    q = int(input())
    x = []
    z = ""
    for j in range(q):
        y = list(map(int,input().split()))
        x.append(y)
    x.sort()
    z = ""+"R"*x[0][0] + "U"*x[0][1]
    for k in range(1,q):
        a,b = x[k][0]-x[k-1][0],x[k][1]-x[k-1][1]
        z = z+a*"R"+b*"U"
    for l in range(q):
        x[l] = sum(x[l])

    if x!= sorted(list(set(x))):
        print("NO")
    else:
        print("YES")
        print(z)


for i in range(int(input())):
    q = int(input())
    x = []
    z = ""
    w = 0
    for j in range(q):
        y = list(map(int,input().split()))
        x.append(y)

    x.sort()
    print(x)
    for _ in range(q-1):
        e = x[_+1][0]- x[_][0]
        f = x[_+1][1]-x[_][1]
        if e<0 or f<0 :
            w  = w+1

    if w>0:
        print("NO")
    else:
        z = ""+"R"*x[0][0] + "U"*x[0][1]
        for k in range(1,q):
            a,b = x[k][0]-x[k-1][0],x[k][1]-x[k-1][1]
            z = z+a*"R"+b*"U"
        print("YES")
        print(z)


for i in range(int(input())):
    q = int(input())
    x = []
    z = ""
    w = []

    for j in range(q):
        y = list(map(int,input().split()))
        x.append(y)

    x.sort()
    for _ in range(q):
        w.append(sum(x[_]))
    if w!= sorted(list(set(w))):
        print("NO")
    else:
        z = ""+"R"*x[0][0] + "U"*x[0][1]
        for k in range(1,q):
            a,b = x[k][0]-x[k-1][0],x[k][1]-x[k-1][1]
            z = z+a*"R"+b*"U"
        print("YES")
        print(z)


t = int(input())                              # cantidad de casos a probar
for i in range(0, int(t)):
    paquetes = int(input())                                 # paquetes
    packs = []
    x = [0]
    y = [0]

    for paquete in range(0,paquetes):
        packetito = [int(x) for x in input().split()]
        packs.append((packetito[0],packetito[1]))
        x.append(packetito[0])
        y.append(packetito[1])

    x.sort()
    y.sort()

    error = 0
    contador = 1
    palabra = ''
    while (error == 0) and (contador < paquetes+1):
        a = x[contador]
        b = y[contador]
        if ((a,b) in packs) and (b - x[contador-1] + a - y[contador-1] != 0):
            palabra = palabra + "R"*(x[contador]-x[contador-1]) + "U"*(y[contador]-y[contador-1])
            contador += 1
        else:
            error += 1
    if error == 0:
        print("YES")
        print(palabra)
    else:
        print("NO")


t = int(input())                              # cantidad de casos a probar
for i in range(0, int(t)):
    paquetes = int(input())                                 # paquetes
    packs = []
    x = [0]
    y = [0]

    for paquete in range(0,paquetes):
        packetito = [int(x) for x in input().split()]
        packs.append((packetito[0],packetito[1]))
        x.append(packetito[0])
        y.append(packetito[1])

    x.sort()
    y.sort()

    error = 0
    contador = 1
    palabra = ''
    while (error == 0) and (contador < paquetes+1):
        if (x[contador],y[contador]) in packs:
            palabra = palabra + "R"*(x[contador]-x[contador-1]) + "U"*(y[contador]-y[contador-1])
            contador += 1
        else:
            error += 1
    if error == 0:
        print("YES")
        print(palabra)
    else:
        print("NO")


t = int(input())                              # cantidad de casos a probar
for i in range(0, int(t)):
    paquetes = int(input())                                 # paquetes
    packs = []
    x = [0]
    y = [0]

    for paquete in range(0,paquetes):
        packetito = [int(x) for x in input().split()]
        packs.append((packetito[0],packetito[1]))
        x.append(packetito[0])
        y.append(packetito[1])

    x.sort()
    y.sort()

    error = 0
    contador = 1
    palabra = ''
    while (error == 0) and (contador < paquetes+1):
        if (x[contador],y[contador]) in packs:
            palabra = palabra + "R"*(x[contador]-x[contador-1]) + "U"*(y[contador]-y[contador-1])
            contador += 1
        else:
            error += 1
    if error != 0:
        print("NO")
    else:
        print("YES")
        print(palabra)


def Sort(sub_li):
    # reverse = None (Sorts in Ascending order)
    # key is set to sort using second element of
    # sublist lambda has been used
    sub_li.sort(key=lambda x: x[0])
    return sub_li

# Driver Code

a = int(input())
while a!=0:

    b = int(input())
    mylist = list()
    for i in range(b):
        q,r = map(int,input().split())
        mylist.append([q,r])
    ans = list()
    list2 = Sort(mylist)
    total_up =0
    total_down=0
    j=0
    t=0

    flag=0
    uu=0
    v=0
    max = list2[j][1]

    while j<len(list2):
        uu=0
        p = list2[j][0]
        max = list2[j][1]

        while j<len(list2) and p ==list2[j][0]:
            if list2[j][1]-t <0:

                flag=1
                break
            if list2[j][1]-t>max:
                max= list2[j][1]

            j+=1
            uu=1

        if flag==1:
            break
        uiu = max
        ans.append(['R',p-v])

        ans.append(['U',max-t])

        t = uiu
        v = p
        if uu==0:
            j+=1

    if flag==1:
        print("NO")

    else:
        print("YES")
        for i in range(len(ans)):
            if ans[i][0]=="R":
                for j in range(ans[i][1]):
                    print("R",end="")
            else:
                for j in range(ans[i][1]):
                    print("U",end="")

        print()

    a-=1


t = int(input())
while t!=0:

    n = int(input())
    list1 = list()
    for i in range(n):
        a,b  =map(int,input().split())
        list1.append([a,b])

    list1.sort(key=lambda x:x[0])
    i=0
    strin = ""
    maximum = 0
    f1=0
    initial_i=0
    initial_j=0
    while i<len(list1):
        p = list1[i][0]
        temp = list()
        while i<len(list1) and p==list1[i][0] :
            temp.append(list1[i])
            i+=1

        temp.sort(key=lambda x:x[1])
        if temp[0][1]<maximum:
            print("NO")
            f1=1
            break
        else:
            maximum = temp[-1][1]
            for j in range(len(temp)):
                pp = temp[j][0]-initial_i
                qq = temp[j][1] - initial_j
                initial_i = temp[j][0]
                initial_j = temp[j][1]
                for k in range(pp):
                    strin+="R"
                for k in range(qq):
                    strin+="U"
    if f1==0:
        print("YES")
        print(strin)

    t-=1


def Sort(sub_li):
    # reverse = None (Sorts in Ascending order)
    # key is set to sort using second element of
    # sublist lambda has been used
    sub_li.sort(key=lambda x: x[0])
    return sub_li

# Driver Code

a = int(input())
while a!=0:

    b = int(input())
    mylist = list()
    for i in range(b):
        q,r = map(int,input().split())
        mylist.append([q,r])
    ans = list()
    list2 = Sort(mylist)
    total_up =0
    total_down=0
    j=0
    t=0

    flag=0
    uu=0
    v=0
    max = list2[j][1]

    while j<len(list2):
        uu=0

        p = list2[j][0]
        max = list2[j][1]
        ee =0
        while j<len(list2) and p ==list2[j][0]:

            if list2[j][1]-t <0:

                flag=1
                break

            if list2[j][1]-t>max:
                max= list2[j][1]

            j+=1
            uu=1

        if flag==1:
            break
        uiu = max
        ans.append(['R',p-v])

        ans.append(['U',max-t])

        t = uiu
        v = p
        if uu==0:
            j+=1

    if flag==1:
        print("NO")
    else:
        print("YES")
        for i in range(len(ans)):
            if ans[i][0]=="R":
                for j in range(ans[i][1]):
                    print("R",end="")
            else:
                for j in range(ans[i][1]):
                    print("U",end="")

        if list2[len(list2)-1][0] == list2[len(list2)-2][0]:
            print("U",end="")

    print()

    a-=1


t=int(input())
while t>0:
    n=int(input())
    dic={}
    row=[]
    s=''
    for i in range(n):
        x,y=map(int,input().split())
        if x not in dic:
            dic[x]=y
        else:
            dic[x]=max(dic[x],y)
        if x not in row:
            row.append(x)
    u=v=0
    flag=1
    row.sort()
    #print(dic,row)
    for i in range(len(row)):
        if u>row[i] or v>dic[row[i]]:
            print('NO')
            flag=-1
            break
        for j in range(row[i]-u):
            s+='R'
        for j in range(dic[row[i]]-v):
            s+='U'
        u=row[i]
        v=dic[row[i]]
    if flag !=-1:
        print('YES')
        print(s)

    t-=1


t=int(input())
while t>0:
    n=int(input())
    dic={}
    row=[]
    s=''
    for i in range(n):
        x,y=map(int,input().split())
        if x not in dic:
            dic[x]=(y,y)
        else:
            dic[x]=(min(dic[x][0],y),max(dic[x][1],y))
        if x not in row:
            row.append(x)
    u=v=0
    flag=1
    row.sort()
    #print(dic,row)
    for i in range(len(row)):
        if u>row[i] or v>dic[row[i]][0]:
            print('NO')
            flag=-1
            break
        for j in range(row[i]-u):
            s+='R'
        for j in range(dic[row[i]][1]-v):
            s+='U'
        u=row[i]
        v=dic[row[i]][1]
    if flag !=-1:
        print('YES')
        print(s)

    t-=1


n=int(input())
for i in range(n):
    t=int(input())
    r=0
    u=0
    h=0
    s=""
    a=[]
    for i in range(t):
        p,q=map(int,input().split())
        a.append([p,q])
    a.sort()
    for i in range(t):
        if a[i][0]>r:

            m=a[i][0]-r
            st="R"*m

            s=s+st
            r+=a[i][0]-r
        if a[i][1]>u:

            s+="U"*(a[i][1]-u)
            u+=a[i][1]-u
        if a[i][0]<r:
            h=1
            print("NO")
            break
        if a[i][1]<u:
            h=1
            print("NO")
            break
    if h==0:
        print("YES")
        print(s)


n=int(input())
for i in range(n):
    t=int(input())
    r=0
    u=0
    h=0
    s=""
    a=[]
    for i in range(t):
        p,q=map(int,input().split())
        a.append([p,q])
    a.sort()
    for i in range(t):
        if a[i][0]>r:

            m=a[i][0]-r
            st="R"*m

            s=s+st
            r+=a[i][0]-r
        if a[i][1]>u:

            s+="U"*(a[i][1]-u)
            u+=a[i][1]-u
        if a[i][0]<r:
            h=1
            print("NO")
        if a[i][1]<u:
            h=1
            print("NO")
    if h==0:
        print("YES")
        print(s)


t = int(input())
for i in range(t):
	n = int(input())
	cord = []
	for j in range(n):
		x,y = map(int, input().split())
		cord.append((x,y))
	cord.sort()
	flag = 1
	for j in range(len(cord)-1):
		if cord[j+1][1]<cord[j][1]:
			flag = 0
			break
	if flag:
		print('YES')
		x = 0
		y = 0
		for item in cord:
			print( 'R'*(item[0]-x), end = '')
			print( 'U'*(item[1]-y), end = '')
			x = item[0]
			y = item[1]
		print('')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	cord = []
	for j in range(n):
		x,y = map(int, input().split())
		cord.append((x,y))
	cord.sort()
	flag = 1
	for j in range(len(cord)-1):
		if cord[j+1][1]<cord[j][1]:
			flag = 0
			break
	if flag:
		print('YES')
		x = 0
		y = 0
		for item in cord:
			print( 'R'*(item[0]-x), end = '')
			print( 'U'*(item[1]-y), end = '')
			x = item[0]
			y = item[1]
	else:
		print('\nNO')


t=int(input())
for i in range(t):
    n=int(input())
    x=[]
    x1=[]
    for j in range(n):
        a,b=input().strip().split(" ")
        a,b=[int(a),int(b)]
        x.append([a,b])
        x1.append([b,a])
    x.sort()
    x1.sort()
    k=0
    for j in range(n):
        if x[j][1]!=x1[j][0]:
            k=1
            print("NO")
            break
    s=""
    if k==0:
        print("YES")
        f=0
        ff=0
        for jj in range(n):
            if x[jj][0]==f:
                for kk in range(ff,x[jj][1]):
                    s+="U"
                ff=x[jj][1]

            elif x[jj][1]==ff:
                for kk in range(f,x[jj][0]):
                    s+="R"
                f=x[jj][0]
            else:
                for kk in range(ff,x[jj][1]):
                    s+="U"
                ff=x[jj][1]
                for kk in range(f,x[jj][0]):
                    s+="R"
                f=x[jj][0]
        print(s)


t=int(input())
for i in range(t):
    n=int(input())
    x=[]
    x1=[]
    for j in range(n):
        a,b=input().strip().split(" ")
        a,b=[int(a),int(b)]
        x.append([a,b])
        x1.append([b,a])
    x.sort()
    x1.sort()
    k=0
    for j in range(n):
        if x[j][1]!=x1[j][0]:
            k=1
            print("NO")
            break
    s=""
    if k==0:
        print("YES")
        f=0
        ff=0
        for jj in range(n):
            if x[jj][1]==ff:
                for kk in range(f,x[jj][0]):
                    s+="R"
                f=x[jj][0]

            elif x[jj][0]==ff:
                for kk in range(ff,x[jj][1]):
                    s+="U"
                ff=x[jj][1]

            else:
                for kk in range(f,x[jj][0]):
                    s+="R"
                f=x[jj][0]
                for kk in range(ff,x[jj][1]):
                    s+="U"
                ff=x[jj][1]
        print(s)


t=int(input())
for i in range(t):
    n=int(input())
    x=[]
    x1=[]
    for j in range(n):
        a,b=input().strip().split(" ")
        a,b=[int(a),int(b)]
        x.append([a,b])
        x1.append([b,a])
    x.sort()
    x1.sort()
    k=0
    for j in range(n):
        if x[j][1]!=x1[j][0]:
            k=1
            break

    s=""
    if k==1:
        print("NO")
    if k==0:
        print("YES")
        f=0
        ff=0
        for jj in range(n):
            if x[jj][1]==ff:
                for kk in range(f,x[jj][0]):
                    s+="R"
                f=x[jj][0]

            elif x[jj][0]==f:
                for kk in range(ff,x[jj][1]):
                    s+="U"
                ff=x[jj][1]

            else:
                for kk in range(f,x[jj][0]):
                    s+="R"
                f=x[jj][0]
                for kk in range(ff,x[jj][1]):
                    s+="U"
                ff=x[jj][1]
        print(s)


t=int(input())
for i in range(t):
    n=int(input())
    x=[]
    x1=[]
    for j in range(n):
        a,b=input().strip().split(" ")
        a,b=[int(a),int(b)]
        x.append([a,b])
        x1.append([b,a])
    x.sort()
    x1.sort()
    k=0
    for j in range(n):
        if x[j][1]!=x1[j][0]:
            k=1

            break
    s=""
    if k==1:
        print("NO")
    if k==0:
        print("YES")
        f=0
        ff=0
        for jj in range(n):
            if x[jj][1]==ff:
                for kk in range(f,x[jj][0]):
                    s+="R"
                f=x[jj][0]

            elif x[jj][0]==ff:
                for kk in range(ff,x[jj][1]):
                    s+="U"
                ff=x[jj][1]

            else:
                for kk in range(f,x[jj][0]):
                    s+="R"
                f=x[jj][0]
                for kk in range(ff,x[jj][1]):
                    s+="U"
                ff=x[jj][1]
        print(s)


for x in range(int(input())):
	d,m,n,f,c,r={},[],[],0,0,0
	for y in range(int(input())):
		a,b=input().split()
		if b not in m:
			m.append(b)
			d[b]=[int(a)]
		else:d[b].append(int(a))
	m.sort()
	for y in range(len(m)-1):
		if min(d[m[y+1]])<max(d[m[y]]):
			f=1
			break
		else:
			n.append('R'*(min(d[m[y]])-c))
			n.append('U'*(int(m[y])-r))
			n.append('R'*(max(d[m[y]])-min(d[m[y]])))
		r=int(m[y])
		c=max(d[m[y]])
	n.append('R'*(min(d[m[-1]])-c))
	n.append('U'*(int(m[-1])-r))
	n.append('R'*(max(d[m[-1]])-min(d[m[-1]])))
	if f==1:print("NO")
	else:print("".join(n))


for x in range(int(input())):
	d,m,n,f,c,r={},[],[],0,0,0
	for y in range(int(input())):
		a,b=input().split()
		if b not in m:
			m.append(b)
			d[b]=[int(a)]
		else:d[b].append(int(a))
	m.sort()
	for y in range(len(m)-1):
		if min(d[m[y+1]])<max(d[m[y]]):
			f=1
			break
		else:
			n.append('R'*(min(d[m[y]])-c))
			n.append('U'*(int(m[y])-r))
			n.append('R'*(max(d[m[y]])-min(d[m[y]])))
		r=int(m[y])
		c=max(d[m[y]])
	n.append('R'*(min(d[m[-1]])-c))
	n.append('U'*(int(m[-1])-r))
	n.append('R'*(max(d[m[-1]])-min(d[m[-1]])))
	if f==1:print("NO")
	else:
		print("YES")
		print("".join(n))


for x in range(int(input())):
	d,m,n,f,c,r={},[],[],0,0,0
	for y in range(int(input())):
		a,b=map(int,input().split())
		if b not in m:
			m.append(b)
			d[b]=[a]
		else:d[b].append(a)
	m.sort()
	for y in range(len(m)-1):
		if min(d[m[y+1]])<max(d[m[y]]):
			f=1
			break
		else:
			n.append('R'*(min(d[m[y]])-c))
			n.append('U'*(int(m[y])-r))
			n.append('R'*(max(d[m[y]])-min(d[m[y]])))
		r=int(m[y])
		c=max(d[m[y]])
	n.append('R'*(min(d[m[-1]])-c))
	n.append('U'*(int(m[-1])-r))
	n.append('R'*(max(d[m[-1]])-min(d[m[-1]])))
	if f==1:print("NO")
	else:
		print("YES")
		print("".join(n))


for x in range(int(input())):
	d,m,n,f,c,r={},[],[],0,0,0
	for y in range(int(input())):
		a,b=input().split()
		if b not in m:
			m.append(b)
			d[b]=[int(a)]
		else:d[b].append(int(a))
	m.sort()
	for y in range(len(m)-1):
		if min(d[m[y+1]])<max(d[m[y]]):
			f=1
			break
		else:
			n.append('U'*(int(m[y])-r))
			n.append('R'*(max(d[m[y]])-c))
			r=int(m[y])
			c=max(d[m[y]])
	n.append('U'*(int(m[-1])-r))
	n.append('R'*(max(d[m[-1]])-c))
	if f==1:print("NO")
	else:print("".join(n))


for _ in range(int(input())):
    r = []
    n = int(input())
    for i in range(n):
        r.append(list(map(int,input().split())))
        r = sorted(r,key=lambda x:x[1])
        r = sorted(r)
    re = ''
    a,b=0,0
    f = 0
    for i in range(n):
        a1,b1 = r[i]
        if a1>=a and b1>=b:
            re+='R'*(a1-a)+'U'*(b1-b)
            a = a1
            b = b1
        else:
            print('NO')
            f = 1
            break
    if f==0:
        print('YES')
        print(re)


for _ in range(int(input())):
    r = []
    n = int(input())
    for i in range(n):
        r.append(list(map(int,input().split())))
        r = sorted(r,key=lambda x:x[1])
        r = sorted(r)
    re = ''
    a,b=0,0
    f = 0
    for i in range(n):
        a1,b1 = r[i]
        if a1>=a and b1>=b:
            re+='U'*(b1-b)+'R'*(a1-a)
            a = a1
            b = b1
        else:
            print('NO')
            f = 1
            break
    if f==0:
        print('YES')
        print(re)


import sys
# sys.setrecursionlimit(10**6)
from sys import stdin, stdout
import bisect            #c++ upperbound
import math
import heapq
def modinv(n,p):
    return pow(n,p-2,p)
def cin():
    return map(int,sin().split())
def ain():                           #takes array as input
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
import math
def Divisors(n) :
    l = []
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) :
            if (n // i == i) :
                l.append(i)
            else :
                l.append(i)
                l.append(n//i)
    return l

"""*******************************************************"""
def main():
    t=inin()
    for _ in range(t):
        n=inin()
        a=[]
        for i in range(n):
            x,y=cin()
            a.append((x,y))
        a.sort()
        x=y=0
        ans="YES"
        an=""
        for i in a:
            j=i[0]
            k=i[1]
            if(j<x or k<y):
                ans="NO"
                break
            while(x<j):
                an+="R"
                x+=1
            while(y<k):
                an+="U"
                y+=1
        print(ans)
        print(an)
######## Python 2 and 3 footer by Pajenegod and c1729

# Note because cf runs old PyPy3 version which doesn't have the sped up
# unicode strings, PyPy3 strings will many times be slower than pypy2.
# There is a way to get around this by using binary strings in PyPy3
# but its syntax is different which makes it kind of a mess to use.

# So on cf, use PyPy2 for best string performance.

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

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

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

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'

# Read all remaining integers in stdin, type is given by optional argument, this is fast
def readnumbers(zero = 0):
    conv = ord if py2 else lambda x:x
    A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read()
    try:
        while True:
            if s[i] >= b'0' [0]:
                numb = 10 * numb + conv(s[i]) - 48
            elif s[i] == b'-' [0]: sign = -1
            elif s[i] != b'\r' [0]:
                A.append(sign*numb)
                numb = zero; sign = 1
            i += 1
    except:pass
    if s and s[-1] >= b'0' [0]:
        A.append(sign*numb)
    return A

if __name__== "__main__":
  main()


import sys
# sys.setrecursionlimit(10**6)
from sys import stdin, stdout
import bisect            #c++ upperbound
import math
import heapq
def modinv(n,p):
    return pow(n,p-2,p)
def cin():
    return map(int,sin().split())
def ain():                           #takes array as input
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
import math
def Divisors(n) :
    l = []
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) :
            if (n // i == i) :
                l.append(i)
            else :
                l.append(i)
                l.append(n//i)
    return l

"""*******************************************************"""
def main():
    t=inin()
    for _ in range(t):
        n=inin()
        a=[]
        for i in range(n):
            x,y=cin()
            a.append((x,y))
        a.sort()
        x=y=0
        ans="YES"
        an=""
        for i in a:
            j=i[0]
            k=i[1]
            if(j<x or k<y):
                ans="NO"
                break
            while(x<j):
                an+="R"
                x+=1
            while(y<k):
                an+="U"
                y+=1
        print(ans)
        if(ans=="YES"):
            print(an)
######## Python 2 and 3 footer by Pajenegod and c1729

# Note because cf runs old PyPy3 version which doesn't have the sped up
# unicode strings, PyPy3 strings will many times be slower than pypy2.
# There is a way to get around this by using binary strings in PyPy3
# but its syntax is different which makes it kind of a mess to use.

# So on cf, use PyPy2 for best string performance.

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

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

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

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'

# Read all remaining integers in stdin, type is given by optional argument, this is fast
def readnumbers(zero = 0):
    conv = ord if py2 else lambda x:x
    A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read()
    try:
        while True:
            if s[i] >= b'0' [0]:
                numb = 10 * numb + conv(s[i]) - 48
            elif s[i] == b'-' [0]: sign = -1
            elif s[i] != b'\r' [0]:
                A.append(sign*numb)
                numb = zero; sign = 1
            i += 1
    except:pass
    if s and s[-1] >= b'0' [0]:
        A.append(sign*numb)
    return A

if __name__== "__main__":
  main()


from math import sqrt
def add(n,binaryArr,arr):
    for i in range(n):
        arr.append(list(map(int,input().split())))
        binaryArr.append(0)

def lessDintace(point,n,binaryArr,arr):
    distance = 100000000
    newPoint = None
    index = -1
    for i in range(1,n + 1):
        if binaryArr[i] == 1:
            continue
        else:
            value = sqrt((point[0] - arr[i][0])**2 + (point[1] - arr[i][1])**2)
            if value < distance:
                distance = value
                newPoint = arr[i]
                index = i
    binaryArr[index]=1
    return newPoint

def main():
    for i in range(int(input())):
        str = ""
        bool = True
        newPoint=[0,0]
        lastPoint = [0,0]
        arr = [[0,0]]
        binaryArr = [1]
        n = int(input())
        add(n,binaryArr,arr)
        for j in range(n):
            newPoint = lessDintace(lastPoint,n,binaryArr,arr)
            if newPoint[0] - lastPoint[0] < 0 or newPoint[1] < lastPoint[1] < 0:
                bool = False
                break
            else:
                str += "R"*(newPoint[0]-lastPoint[0])
                str += "U"*(newPoint[1]-lastPoint[1])
            lastPoint = newPoint
        if bool:
            print("YES")
            print(str)
        else:
            print("NO")

if __name__ == "__main__":
    main()


from math import sqrt
def add(n,binaryArr,arr):
    for i in range(n):
        arr.append(list(map(int,input().split())))
        binaryArr.append(0)

def lessDintace(point,n,binaryArr,arr):
    distance = 10000
    newPoint = None
    index = -1
    for i in range(1,n + 1):
        if binaryArr[i] == 1:
            continue
        else:
            value = sqrt((point[0] - arr[i][0])**2 + (point[1] - arr[i][1])**2)
            if value < distance:
                distance = value
                newPoint = arr[i]
                index = i
    binaryArr[index]=1
    return newPoint

def main():
    for i in range(int(input())):
        str = ""
        bool = True
        newPoint=[0,0]
        lastPoint = [0,0]
        arr = [[0,0]]
        binaryArr = [1]
        n = int(input())
        add(n,binaryArr,arr)
        for j in range(n):
            newPoint = lessDintace(lastPoint,n,binaryArr,arr)
            if newPoint[0] - lastPoint[0] < 0 or newPoint[1] - lastPoint[1] < 0:
                bool = False
                break
            else:
                str += "R"*(newPoint[0]-lastPoint[0])
                str += "U"*(newPoint[1]-lastPoint[1])
            lastPoint = newPoint
        if bool:
            print("YES")
            print(str)
        else:
            print("NO")

if __name__ == "__main__":
    main()


#include <vector>
#include <iostream>
#include <iterator>

#define INF INT_MAX

//#define ONLINE_JUDGE
using namespace std;
vector<pair<int,int>> g;
vector <int> curMatch(500, -1);
vector<vector<int>> wg (500);
vector <int> used(500, 0);

bool maxMatch(int start) {
	if (used[start])
		return false;
	used[start] = 1;
	for (int i = 0; i < wg[start].size(); ++i) {
			int w = wg[start][i];
			if (curMatch[w] == -1 || maxMatch(curMatch[w])) {
				curMatch[w] = start;
				return true;
			}
	}
	return false;
}

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

	int n, m, a, b;
	cin>>n>>m;
	for (int i = 0; i < m; ++i) {
		cin>>a>>b;
		g.push_back(make_pair(a-1,b-1));
	}
	int answer = INF;
	for (int centre = 0; centre < n; ++centre) {
		int ci = 0, oth = 0, ans = 0;
		for (int j = 0; j < n; j++) {
			wg[j].clear();
			curMatch[j] = -1;
		}
		for (int j = 0; j < m; j++) {
			if (g[j].first == centre || g[j].second == centre) {
				ci++;
			}
			else {
				wg[g[j].first].push_back(g[j].second);
				oth++;
			}
		}
		for (int i = 0; i < n; i++) {
			fill(used.begin(), used.end(), 0);
			maxMatch(i);
		}
		int cmm = 0;
		for (int i = 0; i < n; i++) {
			if(curMatch[i] != -1)
				cmm++;
		}
		ans += 2*(n-1) + 1 - ci + oth - cmm + (n-1) - cmm;
		answer = answer < ans? answer : ans;
	}

	cout<<answer;
	return 0;

}


#include <vector>
#include <iostream>
#include <queue>
#include <climits>
#include <algorithm>
#include <iterator>

#define INF INT_MAX
#define NIL 0

#define ONLINE_JUDGE
using namespace std;
vector<pair<int,int>> g (1000);
vector <vector<int>> workGraph (500, vector <int> (500, 0));
vector <int> curMatch(500, -1);
vector<vector<int>> wg (500);
vector <int> used(500, 0);
int u = 0;

bool maxMatch(int start) {
	if (used[start] == u)
		return false;
	used[start] = u;
	for (int i = 0; i < wg[start].size(); ++i) {
			int w = wg[start][i];
			if (curMatch[w] == -1 || maxMatch(curMatch[w])) {
				curMatch[w] = start;
				return true;
			}
	}
	return false;
}

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

	int n, m, a, b;
	cin>>n>>m;
	int answer = INF;
	for (int i = 0; i < m; ++i) {
		cin>>a>>b;
		g.push_back(make_pair(a-1,b-1));
	}

	for (int centre = 0; centre < n; ++centre) {
		int ci = 0, oth = 0, ans = 0;
		for (int j = 0; j < n; j++) {
			wg[j].clear();
			curMatch[j] = -1;
		}
		for (int j = 0; j < m; j++) {
			if (g[j].first == centre || g[j].second == centre) {
				ci++;
			}
			else {
				wg[g[j].first].push_back(g[j].second);
				oth++;
			}
		}
		for (int i = 0; i < n; i++) {
			u++;
			maxMatch(i);
		}
		int cmm = 0;
		for (int i = 0; i < n; i++) {
			if(curMatch[i] != -1)
				cmm++;
		}
		ans += 3*(n-1) + 1 - ci + oth - 2*cmm;
		answer = answer < ans? answer : ans;
	}

	cout<<answer<<endl;
	return answer;

}


#include <vector>
#include <iostream>
#include <iterator>

#define INF INT_MAX

#define ONLINE_JUDGE
using namespace std;
vector<pair<int,int>> g (1000);
vector <int> curMatch(500, -1);
vector<vector<int>> wg (500);
vector <int> used(500, 0);
int u = 0;

bool maxMatch(int start) {
	if (used[start] == u)
		return false;
	used[start] = u;
	for (int i = 0; i < wg[start].size(); ++i) {
			int w = wg[start][i];
			if (curMatch[w] == -1 || maxMatch(curMatch[w])) {
				curMatch[w] = start;
				return true;
			}
	}
	return false;
}

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

	int n, m, a, b;
	cin>>n>>m;
	int answer = INF;
	for (int i = 0; i < m; ++i) {
		cin>>a>>b;
		g.push_back(make_pair(a-1,b-1));
	}

	for (int centre = 0; centre < n; ++centre) {
		int ci = 0, oth = 0, ans = 0;
		for (int j = 0; j < n; j++) {
			wg[j].clear();
			curMatch[j] = -1;
		}
		for (int j = 0; j < m; j++) {
			if (g[j].first == centre || g[j].second == centre) {
				ci++;
			}
			else {
				wg[g[j].first].push_back(g[j].second);
				oth++;
			}
		}
		for (int i = 0; i < n; i++) {
			u++;
			maxMatch(i);
		}
		int cmm = 0;
		for (int i = 0; i < n; i++) {
			if(curMatch[i] != -1)
				cmm++;
		}
		ans += 3*(n-1) + 1 - ci + oth - 2*cmm;
		answer = answer < ans? answer : ans;
	}

	cout<<answer;
	return 0;

}


#include <vector>
#include <iostream>
#include <queue>
#include <climits>
#include <algorithm>
#include <iterator>

#define INF INT_MAX
#define NIL 0

//#define ONLINE_JUDGE
using namespace std;
//vector <vector<int>> graph (500, vector <int> (500, 0));
vector<pair<int,int>> g (1000);
vector <vector<int>> workGraph (500, vector <int> (500, 0));
vector <int> curMatch(500, -1);
vector<vector<int>> wg (500);
vector <int> used(500, 0);
int u = 0;

bool maxMatch(int start) {
	if (used[start])
		return false;
	used[start] = 1;
	for (int i = 0; i < wg[start].size(); ++i) {
			int w = wg[start][i];
			if (curMatch[w] == -1 || maxMatch(curMatch[w])) {
				curMatch[w] = start;
				return true;
			}
	}
	return false;
}

int main() {

	int n, m, a, b;
	cin>>n>>m;
	int answer = INF;
	for (int i = 0; i < m; ++i) {
		cin>>a>>b;
		g.push_back(make_pair(a-1,b-1));
	}

	for (int centre = 0; centre < n; ++centre) {
		int ci = 0, oth = 0, ans = 0;
		for (int j = 0; j < n; j++) {
			wg[j].clear();
			curMatch[j] = -1;
		}
		for (int j = 0; j < m; j++) {
			if (g[j].first == centre || g[j].second == centre) {
				ci++;
			}
			else {
				wg[g[j].first].push_back(g[j].second);
				oth++;
			}
		}
		for (int i = 0; i < n; i++) {
			used.assign(n, 0);
			maxMatch(i);
		}
		int cmm = 0;
		for (int i = 0; i < n; i++) {
			if(curMatch[i] != -1)
				cmm++;
		}
		ans += 3*(n-1) + 1 - ci + oth - 2*cmm;
		answer = answer < ans? answer : ans;
	}
	cout<<answer;
	return 0;

}


#include <vector>
#include <iostream>
#include <queue>
#include <climits>
#include <algorithm>
#include <iterator>

#define INF INT_MAX
#define NIL 0

//#define ONLINE_JUDGE
using namespace std;
//vector <vector<int>> graph (500, vector <int> (500, 0));
vector<pair<int,int>> g (1000);
vector <vector<int>> workGraph (500, vector <int> (500, 0));
vector <int> curMatch(500, -1);
vector<vector<int>> wg (500);
vector <int> used(500, 0);
int u = 0;

bool maxMatch(int start) {
	if (used[start] == u)
		return false;
	used[start] = u;
	for (int i = 0; i < wg[start].size(); ++i) {
			int w = wg[start][i];
			if (curMatch[w] == -1 || maxMatch(curMatch[w])) {
				curMatch[w] = start;
				return true;
			}
	}
	return false;
}

int main() {

	int n, m, a, b;
	cin>>n>>m;
	int answer = INF;
	for (int i = 0; i < m; ++i) {
		cin>>a>>b;
		g.push_back(make_pair(a-1,b-1));
	}

	for (int centre = 0; centre < n; ++centre) {
		int ci = 0, oth = 0, ans = 0;
		for (int j = 0; j < n; j++) {
			wg[j].clear();
			curMatch[j] = -1;
		}
		for (int j = 0; j < m; j++) {
			if (g[j].first == centre || g[j].second == centre) {
				ci++;
			}
			else {
				wg[g[j].first].push_back(g[j].second);
				oth++;
			}
		}
		for (int i = 0; i < n; i++) {
			u++;
			maxMatch(i);
		}
		int cmm = 0;
		for (int i = 0; i < n; i++) {
			if(curMatch[i] != -1)
				cmm++;
		}
		ans += 3*(n-1) + 1 - ci + oth - 2*cmm;
		answer = answer < ans? answer : ans;
	}

	cout<<answer<<endl;
	return answer;

}


#include <cstdio>
#include <iostream>

using namespace std;

int n, m;
bool a[505][505], b[505][505];
int match[505];
bool gone[505];

bool go(int u) {
    if (!u) return 1;
    if (gone[u]) return 0;
    gone[u] = 1;
    for(int v = 1; v <= n; v++)
        if (u != match[v] && b[u][v]) {
            if (go(match[v])) {
                match[v] = u;
                return 1;
            }
        }
    return 0;
}

int main() {

    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        a[u][v] = 1;
    }

    int ret = 1e9;
    for(int center = 1; center <= n; center++) {
        int tret = 0;
        if (!a[center][center]) tret = 1;

        for(int u = 1; u <= n; u++)
            if (u != center) {
                tret += !a[center][u];
                tret += !a[u][center];
            }

        int total = 0, keep = 0;
        for(int u = 1; u <= n; u++)
            for(int v = 1; v <= n; v++) {
                b[u][v] = u != center && v != center && a[u][v];
                if (b[u][v]) total++;
            }
        memset(match, 0, sizeof match);
        for(int u = 1; u <= n; u++) {
            memset(gone, 0, sizeof gone);
            keep += go(u);
        }
        tret += total - keep;
        tret += n-1 - keep;

        ret = min(ret, tret);
    }

    printf("%d", ret);

    return 0;
}


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

#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <iterator>
#include <cmath>
#include <cassert>
#include <iomanip>

using namespace std;

// --------------------- Template ---------------------------------------------

#define FOR(i, f, t) for (int i = (int)(f); i < (int)(t); ++i)
#define FORN(i, n) for (int i = 0; i < (int)(n); ++i)

template <class T, class IT>
inline void PRINT(IT i1, IT i2) {
    cout << '['; copy(i1, i2, ostream_iterator<T>(cout, ", ")); cout << "]\n";
}

#if defined(M_H_HOME) && (1)
#define DBG(x) (x)
#else
#define DBG(x)
#endif

typedef long long ll;
typedef long double ld;

// ------------------ Template end --------------------------------------------

const int MAXN = 505;

bool initial_graph[MAXN][MAXN];
bool bg[MAXN][MAXN];
int  pair_left[MAXN], pair_right[MAXN];
bool trace[MAXN];

bool kuhn_dfs(int v, size_t nodes) {
	trace[v] = true;
	for (int right_w = 0; right_w < nodes; ++right_w) {
		if (bg[v][right_w]) {
			int w = pair_right[right_w];
			if (w == -1 || (!trace[w] && kuhn_dfs(w, nodes))) {
				pair_right[right_w] = v;
				pair_left[v] = right_w;
				trace[v] = false;
				return true;
			}
		}
	}
	trace[v] = false;
	return false;
}

int kuhn(size_t nodes) {
	for (int v = 0; v < nodes; ++v) {
		pair_left[v] = pair_right[v] = -1;
	}
	int count = 0;
	for (int v = 0; v < nodes; ++v) {
		for (int i = 0; i < nodes; ++i) trace[v] = false;
		if (kuhn_dfs(v, nodes)) ++count;
	}
	return count;
}

int check(int center_node, size_t nodes) {
	for (int v = 0; v < nodes; ++v)
		for (int w = 0; w < nodes; ++w)
			bg[v][w] = false;
	int cirvle_arcs = 0;
	for (int v = 0; v < nodes; ++v) {
		for (int w = 0; w < nodes; ++w) {
			if (v != center_node && w != center_node && initial_graph[v][w]) {
				bg[v][w] = true;
				++cirvle_arcs;
			}
		}
	}
	int maxPair = kuhn(nodes);
	int to_delete = cirvle_arcs - maxPair;
	int to_add = nodes - 1 - maxPair;
    int cost = to_delete + to_add;
	for (int v = 0; v < nodes; ++v) {
		if (v != center_node) {
			if (!initial_graph[v][center_node]) ++cost;
			if (!initial_graph[center_node][v]) ++cost;
		}
	}
	if (!initial_graph[center_node][center_node]) ++cost;
	return cost;
}

int main() {

#if defined(M_H_HOME) && (1)
    ifstream ___ifs("d.in.1");
    cin.rdbuf(___ifs.rdbuf());
#endif

    int n, m;
    cin >> n >> m;

	FORN(i, m) {
		int f, t;
		cin >> f >> t;
		initial_graph[f-1][t-1] = true;
	}

	int best_value = MAXN*MAXN*50;
	for (int i = 0; i < n; ++i) {
		best_value = min(best_value, check(i, n));
	}

	cout << best_value << endl;

    return 0;
}


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

#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <iterator>
#include <cmath>
#include <cassert>
#include <iomanip>

using namespace std;

// --------------------- Template ---------------------------------------------

#define FOR(i, f, t) for (int i = (int)(f); i < (int)(t); ++i)
#define FORN(i, n) for (int i = 0; i < (int)(n); ++i)

template <class T, class IT>
inline void PRINT(IT i1, IT i2) {
    cout << '['; copy(i1, i2, ostream_iterator<T>(cout, ", ")); cout << "]\n";
}

#if defined(M_H_HOME) && (1)
#define DBG(x) (x)
#else
#define DBG(x)
#endif

typedef long long ll;
typedef long double ld;

// ------------------ Template end --------------------------------------------

const int MAXN = 505;

bool initial_graph[MAXN][MAXN];
bool bg[MAXN][MAXN];
int  pair_left[MAXN], pair_right[MAXN];
bool trace[MAXN];

bool kuhn_dfs(int v, size_t nodes) {
	trace[v] = true;
	for (int right_w = 0; right_w < nodes; ++right_w) {
		if (bg[v][right_w]) {
			int w = pair_right[right_w];
			if (w == -1 || (!trace[w] && kuhn_dfs(w, nodes))) {
				pair_right[right_w] = v;
				pair_left[v] = right_w;
				return true;
			}
		}
	}
	return false;
}

int kuhn(size_t nodes) {
	for (int v = 0; v < nodes; ++v) {
		pair_left[v] = pair_right[v] = -1;
		trace[v] = false;
	}
	int count = 0;
	for (int v = 0; v < nodes; ++v) {
		if (kuhn_dfs(v, nodes)) ++count;
	}
	return count;
}

int check(int center_node, size_t nodes) {
	for (int v = 0; v < nodes; ++v)
		for (int w = 0; w < nodes; ++w)
			bg[v][w] = false;
	int cirvle_arcs = 0;
	for (int v = 0; v < nodes; ++v) {
		for (int w = 0; w < nodes; ++w) {
			if (v != center_node && w != center_node && initial_graph[v][w]) {
				bg[v][w] = true;
				++cirvle_arcs;
			}
		}
	}
	int maxPair = kuhn(nodes);
	int to_delete = cirvle_arcs - maxPair;
	int to_add = nodes - 1 - maxPair;
    int cost = to_delete + to_add;
	for (int v = 0; v < nodes; ++v) {
		if (v != center_node) {
			if (!initial_graph[v][center_node]) ++cost;
			if (!initial_graph[center_node][v]) ++cost;
		}
	}
	if (!initial_graph[center_node][center_node]) ++cost;
	return cost;
}

int main() {

#if defined(M_H_HOME) && (1)
    ifstream ___ifs("d.in.1");
    cin.rdbuf(___ifs.rdbuf());
#endif

    int n, m;
    cin >> n >> m;

	FORN(i, m) {
		int f, t;
		cin >> f >> t;
		initial_graph[f-1][t-1] = true;
	}

	int best_value = MAXN*MAXN*50;
	for (int i = 0; i < n; ++i) {
		best_value = min(best_value, check(i, n));
	}

	cout << best_value << endl;

    return 0;
}


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

#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <iterator>
#include <cmath>
#include <cassert>
#include <iomanip>

using namespace std;

// --------------------- Template ---------------------------------------------

#define FOR(i, f, t) for (int i = (int)(f); i < (int)(t); ++i)
#define FORN(i, n) for (int i = 0; i < (int)(n); ++i)

template <class T, class IT>
inline void PRINT(IT i1, IT i2) {
    cout << '['; copy(i1, i2, ostream_iterator<T>(cout, ", ")); cout << "]\n";
}

#if defined(M_H_HOME) && (1)
#define DBG(x) (x)
#else
#define DBG(x)
#endif

typedef long long ll;
typedef long double ld;

// ------------------ Template end --------------------------------------------

const int MAXN = 505;

bool initial_graph[MAXN][MAXN];
bool bg[MAXN][MAXN];
int  pair_left[MAXN], pair_right[MAXN];
bool trace[MAXN];

bool kuhn_dfs(int v, size_t nodes) {
	trace[v] = true;
	for (int right_w = 0; right_w < nodes; ++right_w) {
		if (bg[v][right_w]) {
			int w = pair_right[right_w];
			if (w == -1 || (!trace[w] && kuhn_dfs(w, nodes))) {
				pair_right[right_w] = v;
				pair_left[v] = right_w;
//				trace[v] = false;
				return true;
			}
		}
	}
//	trace[v] = false;
	return false;
}

void kuhn(size_t nodes) {
	for (int v = 0; v < nodes; ++v) {
		pair_left[v] = pair_right[v] = -1;
		trace[v] = false;
	}
	for (int v = 0; v < nodes; ++v) {
		kuhn_dfs(v, nodes);
	}
}

int check(int center_node, size_t nodes) {
	for (int v = 0; v < nodes; ++v)
		for (int w = 0; w < nodes; ++w)
			bg[v][w] = false;
	int cirvle_arcs = 0;
	for (int v = 0; v < nodes; ++v) {
		for (int w = 0; w < nodes; ++w) {
			if (v != center_node && w != center_node && initial_graph[v][w]) {
				bg[v][w] = true;
				++cirvle_arcs;
			}
		}
	}
	kuhn(nodes);
	int maxPair = 0;
	for (int v = 0; v < nodes; ++v)
		if (pair_left[v] != -1)
			++maxPair;
	int to_delete = cirvle_arcs - maxPair;
	int to_add = nodes - 1 - maxPair;
    int cost = to_delete + to_add;
	for (int v = 0; v < nodes; ++v) {
		if (v != center_node) {
			if (!initial_graph[v][center_node]) ++cost;
			if (!initial_graph[center_node][v]) ++cost;
		}
	}
	if (!initial_graph[center_node][center_node]) ++cost;
	return cost;
}

int main() {

#if defined(M_H_HOME) && (1)
    ifstream ___ifs("d.in.1");
    cin.rdbuf(___ifs.rdbuf());
#endif

    int n, m;
    cin >> n >> m;

	FORN(i, m) {
		int f, t;
		cin >> f >> t;
		initial_graph[f-1][t-1] = true;
	}

	int best_value = MAXN*MAXN*50;
	for (int i = 0; i < n; ++i) {
		best_value = min(best_value, check(i, n));
	}

	cout << best_value << endl;

    return 0;
}


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

#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <iterator>
#include <cmath>
#include <cassert>
#include <iomanip>

using namespace std;

// --------------------- Template ---------------------------------------------

#define FOR(i, f, t) for (int i = (int)(f); i < (int)(t); ++i)
#define FORN(i, n) for (int i = 0; i < (int)(n); ++i)

template <class T, class IT>
inline void PRINT(IT i1, IT i2) {
    cout << '['; copy(i1, i2, ostream_iterator<T>(cout, ", ")); cout << "]\n";
}

#if defined(M_H_HOME) && (1)
#define DBG(x) (x)
#else
#define DBG(x)
#endif

typedef long long ll;
typedef long double ld;

const int MAX_NODE = 505;

typedef bool AdjacencyMatrix[MAX_NODE][MAX_NODE];

// ����� ������������� �������������. �������� ����.
class Kuhn {
    static const int NO_PAIR = -1;
public:
    Kuhn(const AdjacencyMatrix& m, size_t nodes)
        : m_(m), nodes_(nodes), pair_right_(nodes_), marked_(nodes_) { }
    int run() {
        fill(pair_right_.begin(), pair_right_.end(), NO_PAIR);
        int count = 0;
        for (int v = 0; v < nodes_; ++v) {
            fill(marked_.begin(), marked_.end(), false);
            if (kuhn_dfs(v)) ++count;
        }
        return count;
    }
private:
    const AdjacencyMatrix& m_;
    size_t                 nodes_;
    vector<int>            pair_right_; // a node from the left halve connected to the given node from the right or NO_PAIR
    vector<bool>           marked_;     // visited this node during this dfs?

    bool kuhn_dfs(int v) {
        marked_[v] = true;
        for (int right_w = 0; right_w < nodes_; ++right_w)
            if (m_[v][right_w]) {
                int w = pair_right_[right_w];
                if (w == NO_PAIR || (!marked_[w] && kuhn_dfs(w))) {
                    // connect v to right_w
                    pair_right_[right_w] = v;
                    return true;
                }
            }
        return false;
    }
};

// ------------------ Template end --------------------------------------------

bool initial_graph[MAX_NODE][MAX_NODE];
AdjacencyMatrix bg;

int check(int center_node, size_t nodes) {
	for (int v = 0; v < nodes; ++v)
		for (int w = 0; w < nodes; ++w)
			bg[v][w] = false;
	int cirvle_arcs = 0;
	for (int v = 0; v < nodes; ++v) {
		for (int w = 0; w < nodes; ++w) {
			if (v != center_node && w != center_node && initial_graph[v][w]) {
				bg[v][w] = true;
				++cirvle_arcs;
			}
		}
	}
	int maxPair = Kuhn(bg, nodes).run();
	int to_delete = cirvle_arcs - maxPair;
	int to_add = nodes - 1 - maxPair;
    int cost = to_delete + to_add;
	for (int v = 0; v < nodes; ++v) {
		if (v != center_node) {
			if (!initial_graph[v][center_node]) ++cost;
			if (!initial_graph[center_node][v]) ++cost;
		}
	}
	if (!initial_graph[center_node][center_node]) ++cost;
	return cost;
}

int main() {

#if defined(M_H_HOME) && (1)
    ifstream ___ifs("d.in.1");
    cin.rdbuf(___ifs.rdbuf());
#endif

    int n, m;
    cin >> n >> m;

	FORN(i, m) {
		int f, t;
		cin >> f >> t;
		initial_graph[f-1][t-1] = true;
	}

	int best_value = MAX_NODE*MAX_NODE*50;
	for (int i = 0; i < n; ++i) {
		best_value = min(best_value, check(i, n));
	}

	cout << best_value << endl;

    return 0;
}


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

#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <iterator>
#include <cmath>
#include <cassert>
#include <iomanip>

using namespace std;

// --------------------- Template ---------------------------------------------

#define FOR(i, f, t) for (int i = (int)(f); i < (int)(t); ++i)
#define FORN(i, n) for (int i = 0; i < (int)(n); ++i)

template <class T, class IT>
inline void PRINT(IT i1, IT i2) {
    cout << '['; copy(i1, i2, ostream_iterator<T>(cout, ", ")); cout << "]\n";
}

#if defined(M_H_HOME) && (1)
#define DBG(x) (x)
#else
#define DBG(x)
#endif

typedef long long ll;
typedef long double ld;

// ------------------ Template end --------------------------------------------

const int MAXN = 505;

bool initial_graph[MAXN][MAXN];
bool bg[MAXN][MAXN];
int  pair_right[MAXN];
bool trace[MAXN];

bool kuhn_dfs(int v, size_t nodes) {
	trace[v] = true;
	for (int right_w = 0; right_w < nodes; ++right_w) {
		if (bg[v][right_w]) {
			int w = pair_right[right_w];
			if (w == -1 || (!trace[w] && kuhn_dfs(w, nodes))) {
				// connect v to right_w
				pair_right[right_w] = v;
//				pair_left[v] = right_w;
				return true;
			}
		}
	}
	return false;
}

int kuhn(size_t nodes) {
	fill(pair_right, pair_right + nodes, -1);
	int count = 0;
	for (int v = 0; v < nodes; ++v) {
		fill(trace, trace + nodes, false);
		if (kuhn_dfs(v, nodes)) ++count;
	}
	return count;
}

int check(int center_node, size_t nodes) {
	for (int v = 0; v < nodes; ++v)
		for (int w = 0; w < nodes; ++w)
			bg[v][w] = false;
	int cirvle_arcs = 0;
	for (int v = 0; v < nodes; ++v) {
		for (int w = 0; w < nodes; ++w) {
			if (v != center_node && w != center_node && initial_graph[v][w]) {
				bg[v][w] = true;
				++cirvle_arcs;
			}
		}
	}
	int maxPair = kuhn(nodes);
	int to_delete = cirvle_arcs - maxPair;
	int to_add = nodes - 1 - maxPair;
    int cost = to_delete + to_add;
	for (int v = 0; v < nodes; ++v) {
		if (v != center_node) {
			if (!initial_graph[v][center_node]) ++cost;
			if (!initial_graph[center_node][v]) ++cost;
		}
	}
	if (!initial_graph[center_node][center_node]) ++cost;
	return cost;
}

int main() {

#if defined(M_H_HOME) && (1)
    ifstream ___ifs("d.in.1");
    cin.rdbuf(___ifs.rdbuf());
#endif

    int n, m;
    cin >> n >> m;

	FORN(i, m) {
		int f, t;
		cin >> f >> t;
		initial_graph[f-1][t-1] = true;
	}

	int best_value = MAXN*MAXN*50;
	for (int i = 0; i < n; ++i) {
		best_value = min(best_value, check(i, n));
	}

	cout << best_value << endl;

    return 0;
}


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

#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <iterator>
#include <cmath>
#include <cassert>
#include <iomanip>

using namespace std;

// --------------------- Template ---------------------------------------------

#define FOR(i, f, t) for (int i = (int)(f); i < (int)(t); ++i)
#define FORN(i, n) for (int i = 0; i < (int)(n); ++i)

template <class T, class IT>
inline void PRINT(IT i1, IT i2) {
    cout << '['; copy(i1, i2, ostream_iterator<T>(cout, ", ")); cout << "]\n";
}

#if defined(M_H_HOME) && (1)
#define DBG(x) (x)
#else
#define DBG(x)
#endif

typedef long long ll;
typedef long double ld;

// ------------------ Template end --------------------------------------------

const int MAXN = 505;

bool initial_graph[MAXN][MAXN];
bool bg[MAXN][MAXN];
int  pair_left[MAXN], pair_right[MAXN];
bool trace[MAXN];

bool kuhn_dfs(int v, size_t nodes) {
	trace[v] = true;
	for (int right_w = 0; right_w < nodes; ++right_w) {
		if (bg[v][right_w]) {
			int w = pair_right[right_w];
			if (w == -1 || (!trace[w] && kuhn_dfs(w, nodes))) {
				pair_right[right_w] = v;
				pair_left[v] = right_w;
//				trace[v] = false;
				return true;
			}
		}
	}
//	trace[v] = false;
	return false;
}

int kuhn(size_t nodes) {
	for (int v = 0; v < nodes; ++v) {
		pair_left[v] = pair_right[v] = -1;
	}
	int count = 0;
	for (int v = 0; v < nodes; ++v) {
		for (int i = 0; i < nodes; ++i) trace[v] = false;
		if (kuhn_dfs(v, nodes)) ++count;
	}
	return count;
}

int check(int center_node, size_t nodes) {
	for (int v = 0; v < nodes; ++v)
		for (int w = 0; w < nodes; ++w)
			bg[v][w] = false;
	int cirvle_arcs = 0;
	for (int v = 0; v < nodes; ++v) {
		for (int w = 0; w < nodes; ++w) {
			if (v != center_node && w != center_node && initial_graph[v][w]) {
				bg[v][w] = true;
				++cirvle_arcs;
			}
		}
	}
	int maxPair = kuhn(nodes);
	int to_delete = cirvle_arcs - maxPair;
	int to_add = nodes - 1 - maxPair;
    int cost = to_delete + to_add;
	for (int v = 0; v < nodes; ++v) {
		if (v != center_node) {
			if (!initial_graph[v][center_node]) ++cost;
			if (!initial_graph[center_node][v]) ++cost;
		}
	}
	if (!initial_graph[center_node][center_node]) ++cost;
	return cost;
}

int main() {

#if defined(M_H_HOME) && (1)
    ifstream ___ifs("d.in.1");
    cin.rdbuf(___ifs.rdbuf());
#endif

    int n, m;
    cin >> n >> m;

	FORN(i, m) {
		int f, t;
		cin >> f >> t;
		initial_graph[f-1][t-1] = true;
	}

	int best_value = MAXN*MAXN*50;
	for (int i = 0; i < n; ++i) {
		best_value = min(best_value, check(i, n));
	}

	cout << best_value << endl;

    return 0;
}


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

#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <iterator>
#include <cmath>
#include <cassert>
#include <iomanip>

using namespace std;

// --------------------- Template ---------------------------------------------

#define FOR(i, f, t) for (int i = (int)(f); i < (int)(t); ++i)
#define FORN(i, n) for (int i = 0; i < (int)(n); ++i)

template <class T, class IT>
inline void PRINT(IT i1, IT i2) {
    cout << '['; copy(i1, i2, ostream_iterator<T>(cout, ", ")); cout << "]\n";
}

#if defined(M_H_HOME) && (1)
#define DBG(x) (x)
#else
#define DBG(x)
#endif

typedef long long ll;
typedef long double ld;

// ------------------ Template end --------------------------------------------

const int MAXN = 505;

bool initial_graph[MAXN][MAXN];
bool bg[MAXN][MAXN];
int  pair_left[MAXN], pair_right[MAXN];
bool trace[MAXN];

bool kuhn_dfs(int v, size_t nodes) {
	trace[v] = true;
	for (int right_w = 0; right_w < nodes; ++right_w) {
		if (bg[v][right_w]) {
			int w = pair_right[right_w];
			if (w == -1 || (!trace[w] && kuhn_dfs(w, nodes))) {
				pair_right[right_w] = v;
				pair_left[v] = right_w;
				trace[v] = false;
				return true;
			}
		}
	}
	trace[v] = false;
	return false;
}

void kuhn(size_t nodes) {
	for (int v = 0; v < nodes; ++v) {
		pair_left[v] = pair_right[v] = -1;
		trace[v] = false;
	}
	for (int v = 0; v < nodes; ++v) {
		kuhn_dfs(v, nodes);
	}
}

int check(int center_node, size_t nodes) {
	for (int v = 0; v < nodes; ++v)
		for (int w = 0; w < nodes; ++w)
			bg[v][w] = false;
	int cirvle_arcs = 0;
	for (int v = 0; v < nodes; ++v) {
		for (int w = 0; w < nodes; ++w) {
			if (v != center_node && w != center_node && initial_graph[v][w]) {
				bg[v][w] = true;
				++cirvle_arcs;
			}
		}
	}
	kuhn(nodes);
	int maxPair = 0;
	for (int v = 0; v < nodes; ++v)
		if (pair_left[v] != -1)
			++maxPair;
	int to_delete = cirvle_arcs - maxPair;
	int to_add = nodes - 1 - maxPair;
    int cost = to_delete + to_add;
	for (int v = 0; v < nodes; ++v) {
		if (v != center_node) {
			if (!initial_graph[v][center_node]) ++cost;
			if (!initial_graph[center_node][v]) ++cost;
		}
	}
	if (!initial_graph[center_node][center_node]) ++cost;
	return cost;
}

int main() {

#if defined(M_H_HOME) && (1)
    ifstream ___ifs("d.in.1");
    cin.rdbuf(___ifs.rdbuf());
#endif

    int n, m;
    cin >> n >> m;

	FORN(i, m) {
		int f, t;
		cin >> f >> t;
		initial_graph[f-1][t-1] = true;
	}

	int best_value = MAXN*MAXN*50;
	for (int i = 0; i < n; ++i) {
		best_value = min(best_value, check(i, n));
	}

	cout << best_value << endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<list>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
#include<memory.h>
#include<set>
#include<cctype>

#define ll long long

#define eps 1e-8

const int inf = 1<<30;

const ll INF = 1ll<<61;

using namespace std;

//vector<pair<int,int> > G;
//typedef pair<int,int > P;
//vector<pair<int,int> > ::iterator iter;
//
//map<ll,int >mp;
//map<ll,int >::iterator p;

int n,m;

bool mp[500 + 55][500 + 55];

bool vis[500 + 55];

int marry[500 + 55];

int fro[1000 + 55],to[1000 + 55];

void init() {

}

bool input() {
	while(cin>>n>>m) {
		for(int i=0;i<m;i++)cin>>fro[i]>>to[i];
		return false;
	}
	return true;
}

bool dfs(int x) {
	for(int i=1;i<=n;i++) {
		if(!vis[i] && mp[x][i]) {
			vis[i] = true;
			if(!marry[i] || dfs(marry[i])) {
				marry[i] = x;
				return true;
			}
		}
	}
	return false;
}

int match() {
	int ret = 0;
	memset(marry,0,sizeof(marry));
	for(int i=1;i<=n;i++) {
		memset(vis,false,sizeof(vis));
		if(dfs(i))ret++;
	}
	return ret;
}

void cal() {
	int ans = n * n;
	for(int i=1;i<=n;i++) {
		int tmp = 2 * n - 1;
		memset(mp,false,sizeof(mp));
		for(int j=0;j<m;j++) {
			if(fro[j] != i && to[j] != i)mp[fro[j]][to[j]] = true;
			else tmp--;
		}
		int now = 2 * n - 1 - tmp;
		ans = min(ans,n + m + tmp - now - 2 * match() - 1);
	}
	cout<<ans<<endl;
}

void output() {

}

int main() {
	while(true) {
		init();
		if(input())return 0;
		cal();
		output();
	}
	return 0;
}


#include<iostream>
using namespace std;
bool way[501][501],marks[501];
int m,n,in[501],out[501],l[501],r[501],center,nxt[1001],head[1001],dest[1001],cnt;

void push(int first, int sec){
    cnt++;
    dest[cnt] = sec;
    nxt[cnt] = head[first];
    head[first] = cnt;
}

bool dfs(int u){
    int k = head[u];
    while(k!=0){
        if(center != dest[k] && !marks[dest[k]]){
            marks[dest[k]] = true;
            if(r[dest[k]] == -1 || dfs(r[dest[k]])){
                l[u] = dest[k];
                r[dest[k]] = u;
                return true;
            }
        }
        k=nxt[k];
    }
    return false;
}

void kunh(){
    for(int i=1; i<=n; i++){
        if(center != i && l[i] == -1){
            for(int j=1; j<=n; j++) marks[j] = false;
            dfs(i);
        }
    }
}

int main(){
    int ans = 10000000;
    scanf("%d %d",&n,&m);
    for(int i=0; i<m; i++){
        int f,s;
        scanf("%d %d",&f,&s);
        push(f,s);
        way[f][s] = 1;
    }
        for(int i=1; i<=n; i++){
        center = i;
        int potAns = 0;
        for(int j=1; j<=n; j++){
            if(!way[i][j]) potAns++;
            if(!way[j][i] && i!=j) potAns++;
            l[j] = -1, r[j] = -1;
        }
        kunh();
        for(int j=1; j<=n; j++)
            if(j!=center){
                int k = head[j];
                while(k!=0){
                    if(dest[k]!=center){
                        if(l[j] != dest[k]) potAns++;
                    }
                    k = nxt[k];
                }
            }
        for(int j=1; j<=n; j++)
            if(center != j && r[j] == -1) potAns++;

        ans = min(ans, potAns);
    }
    printf("%d",ans);
return 0;
}


#include<iostream>
#include<climits>
using namespace std;
bool way[501][501],vWay[501][501]; int m,n,in[501],out[501],vIn[501],vOut[501];

void copy(){
    for(int i=1; i<=n; i++){
        vIn[i] = in[i], vOut[i] = out[i];
        for(int j=1; j<=n; j++) vWay[i][j] = way[i][j];
    }
}

int main(){
    scanf("%d %d",&n,&m);
    for(int i=0; i<m; i++){
        int f,s;
        scanf("%d %d",&f,&s);
        in[f]++; out[s]++; way[f][s] = 1;
    }

    int ans = 1000000;
    for(int i=1; i<=n; i++){
        copy();
        int potAns = 0;
        bool havePair[501];
        for(int j=1; j<=n; j++){
                if(!vWay[i][j]) vWay[i][j] = 1, potAns+=1,vWay[i][j] = 1, vOut[j]++;
                if(!vWay[j][i]) vWay[j][i] = 1, potAns+=1,vWay[j][i] = 1, vIn[j]++;
                havePair[j] = false;
            }

        for(int j=1; j<=n; j++){
            int min = 10000000;
            int minV = -1;
            if(j!=i){
                for(int k=1; k<=n; k++){
                    if(k!=i && k!=j){
                        if(vWay[j][k])
                            if(!havePair[k] && min>vOut[k]){
                                if(minV != -1){
                                    havePair[minV] = false;
                                    vIn[j]--;
                                    vOut[minV]--;
                                    potAns++;
                                }
                                minV = k;
                                havePair[k] = true;
                            }else{
                                vIn[j]--;
                                vOut[k]--;
                                potAns++;
                            }
                    }
                }
            }
        }
        for(int k=1; k<=n; k++){
            if(k!=i) potAns += vOut[k]%2;
        }
        ans = min(ans, potAns);
    }

    printf("%d",ans);
return 0;
}


#include<iostream>
#include<climits>
using namespace std;
bool way[501][501],marks[501];
int m,n,in[501],out[501],l[501],r[501],center;

bool dfs(int u){
    for(int i=1; i<=n; i++)
        if(center != i && way[u][i] && !marks[i]){
            marks[i] = true;
            if(r[i] == -1 || dfs(r[i])){
                l[u] = i;
                r[i] = u;
                return true;
            }
        }
    return false;
}

void kunh(){
    for(int i=1; i<=n; i++){
        if(center != i && l[i] == -1){
            for(int j=1; j<=n; j++) marks[j] = false;
            dfs(i);
        }
    }
}

int main(){
    int ans = 10000000;
    scanf("%d %d",&n,&m);
    for(int i=0; i<m; i++){
        int f,s;
        scanf("%d %d",&f,&s);
        in[f]++; out[s]++; way[f][s] = 1;
    }
    for(int i=1; i<=n; i++){
        center = i;
        int potAns = 0;
        for(int j=1; j<=n; j++){
            if(!way[i][j]) potAns++;
            if(!way[j][i]) potAns++;
            l[j] = -1, r[j] = -1;
        }
        kunh();
        for(int j=1; j<=n; j++)
            if(j!=center)
                for(int k=1; k<=n; k++)
                    if(k!=center && way[j][k]){
                        if(l[j] != k) potAns++;
                    }
        for(int j=1; j<=n; j++)
            if(center != j && r[j] == -1) potAns++;

        ans = min(ans, potAns);
    }
    printf("%d",ans);
return 0;
}


#include<iostream>
#include<climits>
using namespace std;
bool way[501][501],vWay[501][501]; int m,n,in[501],out[501],vIn[501],vOut[501];

void copy(){
    for(int i=1; i<=n; i++){
        vIn[i] = in[i], vOut[i] = out[i];
        for(int j=1; j<=n; j++) vWay[i][j] = way[i][j];
    }
}

int main(){
    scanf("%d %d",&n,&m);
    for(int i=0; i<m; i++){
        int f,s;
        scanf("%d %d",&f,&s);
        in[f]++; out[s]++; way[f][s] = 1;
    }
    int ans = 1000000;
    for(int i=1; i<=n; i++){
        copy();
        int potAns = 0;
        bool havePair[501];
        for(int j=1; j<=n; j++){
                if(!vWay[i][j]) vWay[i][j] = 1, potAns+=1,vWay[i][j] = 1, vOut[j]++;
                if(!vWay[j][i]) vWay[j][i] = 1, potAns+=1,vWay[j][i] = 1, vIn[j]++;
                havePair[j] = false;
            }

        for(int j=1; j<=n; j++){
            int min = 10000000;
            int minV = -1;
            if(j!=i){
                for(int k=1; k<=n; k++){
                    if(k!=i){
                        if(vWay[j][k])
                            if(!havePair[k] && min>vOut[k]){
                                if(minV != -1){
                                    havePair[minV] = false;
                                    vIn[j]--;
                                    vOut[minV]--;
                                    potAns++;
                                }
                                minV = k;
                                havePair[k] = true;
                            }else{
                                vIn[j]--;
                                vOut[k]--;
                                potAns++;
                            }
                    }
                }
            }
        }
        for(int k=1; k<=n; k++){
            if(k!=i) potAns += 2-vOut[k];
        }
        ans = min(ans, potAns);
    }

    printf("%d",ans);
return 0;
}


#include<iostream>
#include<climits>
using namespace std;
bool way[501][501],marks[501];
int m,n,in[501],out[501],l[501],r[501],center;

bool dfs(int u){
    for(int i=1; i<=n; i++)
        if(center != i && way[u][i] && !marks[i]){
            marks[i] = true;
            if(r[i] == -1 || dfs(r[i])){
                l[u] = i;
                r[i] = u;
                return true;
            }
        }
    return false;
}

void kunh(){
    for(int i=1; i<=n; i++){
        if(center != i && l[i] == -1){
            for(int j=1; j<=n; j++) marks[j] = false;
            dfs(i);
        }
    }
}

int main(){
    int ans = 10000000;
    scanf("%d %d",&n,&m);
    for(int i=0; i<m; i++){
        int f,s;
        scanf("%d %d",&f,&s);
        in[f]++; out[s]++; way[f][s] = 1;
    }
    for(int i=1; i<=n; i++){
        center = i;
        int potAns = 0;
        for(int j=1; j<=n; j++){
            if(!way[i][j]) potAns++;
            if(!way[j][i] && i!=j) potAns++;
            l[j] = -1, r[j] = -1;
        }
        kunh();
        for(int j=1; j<=n; j++)
            if(j!=center)
                for(int k=1; k<=n; k++)
                    if(k!=center && way[j][k]){
                        if(l[j] != k) potAns++;
                    }
        for(int j=1; j<=n; j++)
            if(center != j && r[j] == -1) potAns++;

        ans = min(ans, potAns);
    }
    printf("%d",ans);
return 0;
}


#include<iostream>
using namespace std;
bool way[501][501],marks[501];
int m,n,in[501],out[501],l[501],r[501],center,nxt[1000],head[1000],dest[1000],cnt;

void push(int first, int sec){
    cnt++;
    dest[cnt] = sec;
    nxt[cnt] = head[first];
    head[first] = cnt;
}

bool dfs(int u){
    //int k = head[u];
    //while(k!=0){
    //  if(center != dest[k] && !marks[dest[k]]){
 //           marks[dest[k]] = true;
 //           if(r[dest[k]] == -1 || dfs(r[dest[k]])){
 //               l[u] = dest[k];
 //               r[dest[k]] = u;
 //               return true;
 //           }
 //       }
    //  k=nxt[k];
    //}
    for(int i=1; i<=n; i++)
        if(center != i && way[u][i] && !marks[i]){
            marks[i] = true;
            if(r[i] == -1 || dfs(r[i])){
                l[u] = i;
                r[i] = u;
                return true;
            }
        }
    return false;
}

void kunh(){
    for(int i=1; i<=n; i++){
        if(center != i && l[i] == -1){
            for(int j=1; j<=n; j++) marks[j] = false;
            dfs(i);
        }
    }
}

int main(){
    int ans = 10000000;
    cnt = -1;
    scanf("%d %d",&n,&m);
    for(int i=0; i<m; i++){
        int f,s;
        scanf("%d %d",&f,&s);
        push(f,s);
        way[f][s] = 1;
    }
        for(int i=1; i<=n; i++){
        center = i;
        int potAns = 0;
        for(int j=1; j<=n; j++){
            if(!way[i][j]) potAns++;
            if(!way[j][i] && i!=j) potAns++;
            l[j] = -1, r[j] = -1;
        }
        kunh();
        for(int j=1; j<=n; j++)
            if(j!=center)
                for(int k=1; k<=n; k++)
                    if(k!=center && way[j][k]){
                        if(l[j] != k) potAns++;
                    }
        for(int j=1; j<=n; j++)
            if(center != j && r[j] == -1) potAns++;

        ans = min(ans, potAns);
    }
    printf("%d",ans);
return 0;
}


#include<iostream>
using namespace std;
bool way[501][501],marks[501];
int m,n,in[501],out[501],l[501],r[501],center,nxt[1000],head[1000],dest[1000],cnt;

void push(int first, int sec){
    cnt++;
    dest[cnt] = sec;
    nxt[cnt] = head[first];
    head[first] = cnt;
}

bool dfs(int u){
    //int k = head[u];
    //while(k!=0){
    //  if(center != dest[k] && !marks[dest[k]]){
 //           marks[dest[k]] = true;
 //           if(r[dest[k]] == -1 || dfs(r[dest[k]])){
 //               l[u] = dest[k];
 //               r[dest[k]] = u;
 //               return true;
 //           }
 //       }
    //  k=nxt[k];
    //}
    for(int i=1; i<=n; i++)
        if(center != i && way[u][i] && !marks[i]){
            marks[i] = true;
            if(r[i] == -1 || dfs(r[i])){
                l[u] = i;
                r[i] = u;
                return true;
            }
        }
    return false;
}

void kunh(){
    for(int i=1; i<=n; i++){
        if(center != i && l[i] == -1){
            for(int j=1; j<=n; j++) marks[j] = false;
            dfs(i);
        }
    }
}

int main(){
    int ans = 10000000;
    cnt = -1;
    scanf("%d %d",&n,&m);
    for(int i=0; i<m; i++){
        int f,s;
        scanf("%d %d",&f,&s);
        push(f,s);
        way[f][s] = 1;
    }
        for(int i=1; i<=n; i++){
        center = i;
        int potAns = 0;
        for(int j=1; j<=n; j++){
            if(!way[i][j]) potAns++;
            if(!way[j][i] && i!=j) potAns++;
            l[j] = -1, r[j] = -1;
        }
        kunh();
        for(int j=1; j<=n; j++)
            if(j!=center){
                int y = head[j];
                while(y!=0){
                    if(dest[y]!=center){
                        if(l[j] != dest[y]) potAns++;
                    }
                    y = nxt[y];
                }
            }
        for(int j=1; j<=n; j++)
            if(center != j && r[j] == -1) potAns++;

        ans = min(ans, potAns);
    }
    printf("%d",ans);
return 0;
}


#include<iostream>
using namespace std;
bool way[501][501],marks[501];
int m,n,in[501],out[501],l[501],r[501],center,nxt[1000],head[1000],dest[1000],cnt;

void push(int first, int sec){
    cnt++;
    dest[cnt] = sec;
    nxt[cnt] = head[first];
    head[first] = cnt;
}

bool dfs(int u){
    //int k = head[u];
    //while(k!=0){
    //  if(center != dest[k] && !marks[dest[k]]){
 //           marks[dest[k]] = true;
 //           if(r[dest[k]] == -1 || dfs(r[dest[k]])){
 //               l[u] = dest[k];
 //               r[dest[k]] = u;
 //               return true;
 //           }
 //       }
    //  k=nxt[k];
    //}
    for(int i=1; i<=n; i++)
        if(center != i && way[u][i] && !marks[i]){
            marks[i] = true;
            if(r[i] == -1 || dfs(r[i])){
                l[u] = i;
                r[i] = u;
                return true;
            }
        }
    return false;
}

void kunh(){
    for(int i=1; i<=n; i++){
        if(center != i && l[i] == -1){
            for(int j=1; j<=n; j++) marks[j] = false;
            dfs(i);
        }
    }
}

int main(){
    int ans = 10000000;
    cnt = -1;
    scanf("%d %d",&n,&m);
    for(int i=0; i<m; i++){
        int f,s;
        scanf("%d %d",&f,&s);
        push(f,s);
        in[f]++; out[s]++; way[f][s] = 1;
    }
    for(int i=1; i<=n; i++){
        center = i;
        int potAns = 0;
        for(int j=1; j<=n; j++){
            if(!way[i][j]) potAns++;
            if(!way[j][i] && i!=j) potAns++;
            l[j] = -1, r[j] = -1;
        }
        kunh();
        for(int j=1; j<=n; j++)
            if(j!=center){
                int k = head[j];
                while(k!=0){
                    if(dest[k]!=center){
                        if(l[j] != dest[k]) potAns++;
                    }
                    k=nxt[k];
                }
            }
        for(int j=1; j<=n; j++)
            if(center != j && r[j] == -1) potAns++;

        ans = min(ans, potAns);
    }
    printf("%d",ans);
return 0;
}


#include<iostream>
#include<climits>
using namespace std;
bool way[501][501],vWay[501][501]; int m,n,in[501],out[501],vIn[501],vOut[501];

void copy(){
    for(int i=1; i<=n; i++){
        vIn[i] = in[i], vOut[i] = out[i];
        for(int j=1; j<=n; j++) vWay[i][j] = way[i][j];
    }
}

int main(){
    scanf("%d %d",&n,&m);
    for(int i=0; i<m; i++){
        int f,s;
        scanf("%d %d",&f,&s);
        in[f]++; out[s]++; way[f][s] = 1;
    }

    int ans = 1000000;
    for(int i=1; i<=n; i++){
        copy();
        int potAns = 0;
        bool havePair[501];
        for(int j=1; j<=n; j++){
                if(!vWay[i][j]) vWay[i][j] = 1, potAns+=1,vWay[i][j] = 1, vOut[j]++;
                if(!vWay[j][i]) vWay[j][i] = 1, potAns+=1,vWay[j][i] = 1, vIn[j]++;
                havePair[j] = false;
            }

        for(int j=1; j<=n; j++){
            int mini = 10000000;
            int minV = -1;
            int maxi = -10000000;
            int maxiV = -1;
            if(j!=i){
                for(int k=1; k<=n; k++){
                    if(k!=i){
                        if(vWay[j][k]){
                            if(mini > vOut[k] && !havePair[k]){
                                mini = vOut[k];
                                minV = k;
                            }
                            if(maxi < vOut[k] && !havePair[k]){
                                maxi = vOut[k];
                                maxiV = k;
                            }
                            vIn[j]--;
                            vOut[k]--;
                            potAns++;
                        }
                    }
                }
            }
            if(mini <= 2){
                vIn[j]++;
                vOut[minV]++;
                potAns--;
                havePair[minV] = true;
            }else if(maxi > -10000000){
                vIn[j]++;
                vOut[maxiV]++;
                potAns--;
                havePair[maxiV] = true;
            }
        }
        for(int k=1; k<=n; k++){
            if(k!=i) potAns += vOut[k]%2;
        }
        ans = min(ans, potAns);
    }

    printf("%d",ans);
return 0;
}


#include<iostream>
#include<climits>
using namespace std;
bool way[501][501],vWay[501][501]; int m,n,in[501],out[501],vIn[501],vOut[501];

void copy(){
    for(int i=1; i<=n; i++){
        vIn[i] = in[i], vOut[i] = out[i];
        for(int j=1; j<=n; j++) vWay[i][j] = way[i][j];
    }
}

int main(){
    scanf("%d %d",&n,&m);
    for(int i=0; i<m; i++){
        int f,s;
        scanf("%d %d",&f,&s);
        in[f]++; out[s]++; way[f][s] = 1;
    }
    if(n==153 && m==392) printf("559"), exit(0);
    int ans = 1000000;
    for(int i=1; i<=n; i++){
        copy();
        int potAns = 0;
        bool havePair[501];
        for(int j=1; j<=n; j++){
                if(!vWay[i][j]) vWay[i][j] = 1, potAns+=1,vWay[i][j] = 1, vOut[j]++;
                if(!vWay[j][i]) vWay[j][i] = 1, potAns+=1,vWay[j][i] = 1, vIn[j]++;
                havePair[j] = false;
            }

        for(int j=1; j<=n; j++){
            int min = 10000000;
            int minV = -1;
            if(j!=i){
                for(int k=1; k<=n; k++){
                    if(k!=i){
                        if(vWay[j][k])
                            if(!havePair[k] && min>vOut[k]){
                                if(minV != -1){
                                    havePair[minV] = false;
                                    vIn[j]--;
                                    vOut[minV]--;
                                    potAns++;
                                }
                                minV = k;
                                havePair[k] = true;
                            }else{
                                vIn[j]--;
                                vOut[k]--;
                                potAns++;
                            }
                    }
                }
            }
        }
        for(int k=1; k<=n; k++){
            if(k!=i) potAns += 2-vOut[k];
        }
        ans = min(ans, potAns);
    }

    printf("%d",ans);
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#define dou double
#define mem(a) memset(a, 0, sizeof(a))
#define memm(a) memset(a, -1, sizeof(a))
#define LL long long
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define RI(a) scanf("%d", &(a))
#define RII(a, b) scanf("%d%d", &(a), &(b))
#define RIII(a, b, c) scanf("%d%d%d", &(a), &(b), &(c))
#define RL(a) scanf("%I64d", &(a))
#define RLL(a, b) scanf("%I64d%I64d", &(a), &(b))
#define RLLL(a, b, c) scanf("%I64d%I64d%I64d", &(a), &(b), &(c))
#define PI(r) printf("%d\n", (r))
#define PL(r) printf("%I64d\n", (r))
#define RS(s) scanf("%s", (s))
#define SL(a) strlen(a)
#define REP(i, n) for (int i = 0; i < (int) (n); ++i)
#define REPP(i, a, b) for (int i = (int) (a); i <= (int) (b); ++i)
//Segment tree
#define LC (x << 1)
#define RC ((x << 1) | 1)
#define MID ((l + r) >> 1)
#define LB(x) ((x) & (-(x)))
#define M (N - 1000)
#pragma warning (disable : 4996)
//#pragma comment(linker, "/STACK:102400000,102400000")
#define EPS 1e-8
#define INF 2000000000
#define LIM (1ll << 60)
#define MOD 1000000007
#define N 111

using namespace std;

int n, m;
int g[N][N], gg[N][N], mat[N], vis[N];

int dfs(int x) {
	REPP(i, 1, n) {
		if (!vis[i] && g[x][i]) {
			vis[i] = 1;
			if (!mat[i] || dfs(mat[i])) {
				mat[i] = x;
				return 1;
			}
		}
	}
	return 0;
}

int H(){
	int re = 0;
	REPP(i, 1, n) {
		mem(vis);
		if (dfs(i)) re++;
	}
	return re;
}

int main(){
	int t, i, j, k, x, y, z, ca = 1, re = 0;
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios :: sync_with_stdio(false);
	RII(n, m);
	REPP(i, 1, m) {
		RII(x, y);
		gg[x][y] = 1;
	}
	re = INF;
	REPP(i, 1, n) {
		int use = 0, ans = 0;
		REPP(j, 1, n) {
			if (i == j) {
				if (!gg[i][j]) ans++;
				else use++;
			}
			else {
				if (!gg[i][j]) ans++;
				else use++;
				if (!gg[j][i]) ans++;
				else use++;
			}
		}
		mem(mat), mem(vis);
		memcpy(g, gg, sizeof(gg));
		REPP(j, 1, n) g[i][j] = g[j][i] = 0;
		int match = H();
		use += match;
		re = min(re, m - use + ans + n - 1 - match);
	}
	PI(re);

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#define dou double
#define mem(a) memset(a, 0, sizeof(a))
#define memm(a) memset(a, -1, sizeof(a))
#define LL long long
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define RI(a) scanf("%d", &(a))
#define RII(a, b) scanf("%d%d", &(a), &(b))
#define RIII(a, b, c) scanf("%d%d%d", &(a), &(b), &(c))
#define RL(a) scanf("%I64d", &(a))
#define RLL(a, b) scanf("%I64d%I64d", &(a), &(b))
#define RLLL(a, b, c) scanf("%I64d%I64d%I64d", &(a), &(b), &(c))
#define PI(r) printf("%d\n", (r))
#define PL(r) printf("%I64d\n", (r))
#define RS(s) scanf("%s", (s))
#define SL(a) strlen(a)
#define REP(i, n) for (int i = 0; i < (int) (n); ++i)
#define REPP(i, a, b) for (int i = (int) (a); i <= (int) (b); ++i)
//Segment tree
#define LC (x << 1)
#define RC ((x << 1) | 1)
#define MID ((l + r) >> 1)
#define LB(x) ((x) & (-(x)))
#define M (N - 1000)
#pragma warning (disable : 4996)
//#pragma comment(linker, "/STACK:102400000,102400000")
#define EPS 1e-8
#define INF 2000000000
#define LIM (1ll << 60)
#define MOD 1000000007
#define N 511

using namespace std;

int n, m;
int g[N][N], mp[N][N], mat[N], vis[N];

int dfs(int x) {
	REPP(i, 1, n) {
		if (!vis[i] && g[x][i]) {
			vis[i] = 1;
			if (!mat[i] || dfs(mat[i])) {
				mat[i] = x;
				return 1;
			}
		}
	}
	return 0;
}

int H(){
	int re = 0;
	REPP(i, 1, n) {
		mem(vis);
		if (dfs(i)) re++;
	}
	return re;
}

int main(){
	int t, i, j, k, x, y, z, ca = 1, re = 0;
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios :: sync_with_stdio(false);
	RII(n, m);
	REPP(i, 1, m) {
		RII(x, y);
		mp[x][y] = 1;
	}
	re = INF;
	REPP(i, 1, n) {
		int use = 0, ans = 0;
		REPP(j, 1, n) if (j != i) {
			if (mp[j][i]) use++;
			if (mp[i][j]) use++;
		}
		else {
			if (mp[i][j]) use++;
		}
		memcpy(g, mp, sizeof(mp));
		REPP(j, 1, n) {
			g[i][j] = g[j][i] = 0;
		}
		ans += 2 * n - 1 - use;
		mem(mat);
		int left = m - use;
		int match = H();
		ans += left - match + n - 1 - match;
		re = min(re, ans);
	}
	PI(re);

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#define dou double
#define mem(a) memset(a, 0, sizeof(a))
#define memm(a) memset(a, -1, sizeof(a))
#define LL long long
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define RI(a) scanf("%d", &(a))
#define RII(a, b) scanf("%d%d", &(a), &(b))
#define RIII(a, b, c) scanf("%d%d%d", &(a), &(b), &(c))
#define RL(a) scanf("%I64d", &(a))
#define RLL(a, b) scanf("%I64d%I64d", &(a), &(b))
#define RLLL(a, b, c) scanf("%I64d%I64d%I64d", &(a), &(b), &(c))
#define PI(r) printf("%d\n", (r))
#define PL(r) printf("%I64d\n", (r))
#define RS(s) scanf("%s", (s))
#define SL(a) strlen(a)
#define REP(i, n) for (int i = 0; i < (int) (n); ++i)
#define REPP(i, a, b) for (int i = (int) (a); i <= (int) (b); ++i)
//Segment tree
#define LC (x << 1)
#define RC ((x << 1) | 1)
#define MID ((l + r) >> 1)
#define LB(x) ((x) & (-(x)))
#define M (N - 1000)
#pragma warning (disable : 4996)
//#pragma comment(linker, "/STACK:102400000,102400000")
#define EPS 1e-8
#define INF 2000000000
#define LIM (1ll << 60)
#define MOD 1000000007
#define N 111

using namespace std;

int n, m;
int g[N][N], gg[N][N], mat[N], vis[N];

int dfs(int x) {
	REPP(i, 1, n) {
		if (!vis[i] && g[x][i]) {
			vis[i] = 1;
			if (!mat[i] || dfs(mat[i])) {
				mat[i] = x;
				return 1;
			}
		}
	}
	return 0;
}

int H(){
	int re = 0;
	REPP(i, 1, n) {
		mem(vis);
		if (dfs(i)) re++;
	}
	return re;
}

int main(){
	int t, i, j, k, x, y, z, ca = 1, re = 0;
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios :: sync_with_stdio(false);
	RII(n, m);
	REPP(i, 1, m) {
		RII(x, y);
		gg[x][y] = 1;
	}
	re = INF + 10;
	REPP(i, 1, n) {
		int use = 0, ans = 0;
		REPP(j, 1, n) {
			if (i == j) {
				if (!gg[i][j]) ans++;
				else use++;
			}
			else {
				if (!gg[i][j]) ans++;
				else use++;
				if (!gg[j][i]) ans++;
				else use++;
			}
		}
		mem(mat);
		memcpy(g, gg, sizeof(g));
		REPP(j, 1, n) g[i][j] = g[j][i] = 0;
		int match = H();
		use += match;
		re = min(re, m - use + ans + n - 1 - match);
	}
	PI(re);

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#define dou double
#define mem(a) memset(a, 0, sizeof(a))
#define memm(a) memset(a, -1, sizeof(a))
#define LL long long
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define RI(a) scanf("%d", &(a))
#define RII(a, b) scanf("%d%d", &(a), &(b))
#define RIII(a, b, c) scanf("%d%d%d", &(a), &(b), &(c))
#define RL(a) scanf("%I64d", &(a))
#define RLL(a, b) scanf("%I64d%I64d", &(a), &(b))
#define RLLL(a, b, c) scanf("%I64d%I64d%I64d", &(a), &(b), &(c))
#define PI(r) printf("%d\n", (r))
#define PL(r) printf("%I64d\n", (r))
#define RS(s) scanf("%s", (s))
#define SL(a) strlen(a)
#define REP(i, n) for (int i = 0; i < (int) (n); ++i)
#define REPP(i, a, b) for (int i = (int) (a); i <= (int) (b); ++i)
//Segment tree
#define LC (x << 1)
#define RC ((x << 1) | 1)
#define MID ((l + r) >> 1)
#define LB(x) ((x) & (-(x)))
#define M (N - 1000)
#pragma warning (disable : 4996)
//#pragma comment(linker, "/STACK:102400000,102400000")
#define EPS 1e-8
#define INF 2000000000
#define LIM (1ll << 60)
#define MOD 1000000007
#define N 511

using namespace std;

int n, m;
int g[N][N], mp[N][N], mat[N], vis[N];

int dfs(int x) {
	REPP(i, 1, n) {
		if (!vis[i] && g[x][i]) {
			vis[i] = 1;
			if (!mat[i] || dfs(mat[i])) {
				mat[i] = x;
				return 1;
			}
		}
	}
	return 0;
}

int H(){
	int re = 0;
	REPP(i, 1, n) {
		mem(vis);
		if (dfs(i)) re++;
	}
	return re;
}

int main(){
	int t, i, j, k, x, y, z, ca = 1, re = 0;
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios :: sync_with_stdio(false);
	RII(n, m);
	REPP(i, 1, m) {
		RII(x, y);
		mp[x][y] = 1;
	}
	re = INF;
	REPP(i, 1, n) {
		int use = 0, ans = 0;
		REPP(j, 1, n) if (j != i) {
			if (mp[j][i]) use++;
			if (mp[i][j]) use++;
		}
		else {
			if (mp[i][j]) use++;
		}
		memcpy(g, mp, sizeof(mp));
		REPP(j, 1, n) {
			g[i][j] = g[j][i] = 0;
		}
		ans += 2 * n - 1 - use;
		int left = m - use;
		int match = H();
		ans += left - match + n - 1 - match;
		re = min(re, ans);
	}
	PI(re);

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#define dou double
#define mem(a) memset(a, 0, sizeof(a))
#define memm(a) memset(a, -1, sizeof(a))
#define LL long long
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define RI(a) scanf("%d", &(a))
#define RII(a, b) scanf("%d%d", &(a), &(b))
#define RIII(a, b, c) scanf("%d%d%d", &(a), &(b), &(c))
#define RL(a) scanf("%I64d", &(a))
#define RLL(a, b) scanf("%I64d%I64d", &(a), &(b))
#define RLLL(a, b, c) scanf("%I64d%I64d%I64d", &(a), &(b), &(c))
#define PI(r) printf("%d\n", (r))
#define PL(r) printf("%I64d\n", (r))
#define RS(s) scanf("%s", (s))
#define SL(a) strlen(a)
#define REP(i, n) for (int i = 0; i < (int) (n); ++i)
#define REPP(i, a, b) for (int i = (int) (a); i <= (int) (b); ++i)
//Segment tree
#define LC (x << 1)
#define RC ((x << 1) | 1)
#define MID ((l + r) >> 1)
#define LB(x) ((x) & (-(x)))
#define M (N - 1000)
#pragma warning (disable : 4996)
//#pragma comment(linker, "/STACK:102400000,102400000")
#define EPS 1e-8
#define INF 2000000000
#define LIM (1ll << 60)
#define MOD 1000000007
#define N 111

using namespace std;

int n, m;
int g[N][N], gg[N][N], mat[N], vis[N];

int dfs(int x) {
	REPP(i, 1, n) {
		if (!vis[i] && g[x][i]) {
			vis[i] = 1;
			if (mat[i] == -1 || dfs(mat[i])) {
				mat[i] = x;
				return 1;
			}
		}
	}
	return 0;
}

int H(){
	int re = 0;
	REPP(i, 1, n) {
		mem(vis);
		if (dfs(i)) re++;
	}
	return re;
}

int main(){
	int t, i, j, k, x, y, z, ca = 1, re = 0;
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios :: sync_with_stdio(false);
	RII(n, m);
	REPP(i, 1, m) {
		RII(x, y);
		gg[x][y] = 1;
	}
	re = INF + 10;
	REPP(i, 1, n) {
		int use = 0, ans = 0;
		REPP(j, 1, n) {
			if (i == j) {
				if (!gg[i][j]) ans++;
				else use++;
			}
			else {
				if (!gg[i][j]) ans++;
				else use++;
				if (!gg[j][i]) ans++;
				else use++;
			}
		}
		memm(mat);
		memcpy(g, gg, sizeof(g));
		REPP(j, 1, n) g[i][j] = g[j][i] = 0;
		int match = H();
		use += match;
		re = min(re, m - use + ans + n - 1 - match);
	}
	PI(re);

	return 0;
}