Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include<stdio.h>

int N, M;
int V[100000];

int root(int x) {
  if(V[x] == -1) return x;
  else return V[x] = root(V[x]);
}

void merge(int a, int b) {
  a = root(a);
  b = root(b);
  if(a == b) return;
  V[a] = b;
}

int main() {
  int unique[100000] = {};
  scanf("%d%d", &N, &M);
  for(int i = 0;i < N;i++) V[i] = -1;
  for(int i = 0;i < M;i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--; b--;
    merge(a, b);
  }
  int ans = -1;
  for(int i = 0;i < N;i++) {
    if(unique[root(i)]++ == 0) ans++;
  }
  printf("%d\n", ans);
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	N
	.bss
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	V
	.align 32
	.type	V, @object
	.size	V, 400000
V:
	.zero	400000
	.text
	.globl	root
	.type	root, @function
root:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	V(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	jne	.L2
	movl	-4(%rbp), %eax
	jmp	.L3
.L2:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	V(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %edi
	call	root
	movl	-4(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	V(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	V(%rip), %rax
	movl	(%rdx,%rax), %eax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	root, .-root
	.globl	merge
	.type	merge, @function
merge:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, %edi
	call	root
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, %edi
	call	root
	movl	%eax, -8(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-8(%rbp), %eax
	je	.L7
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	V(%rip), %rdx
	movl	-8(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	jmp	.L4
.L7:
	nop
.L4:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	merge, .-merge
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-397312(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2736, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-400016(%rbp), %rax
	movl	$400000, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	M(%rip), %rax
	movq	%rax, %rdx
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -400032(%rbp)
	jmp	.L9
.L10:
	movl	-400032(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	V(%rip), %rax
	movl	$-1, (%rdx,%rax)
	addl	$1, -400032(%rbp)
.L9:
	movl	N(%rip), %eax
	cmpl	%eax, -400032(%rbp)
	jl	.L10
	movl	$0, -400028(%rbp)
	jmp	.L11
.L12:
	leaq	-400036(%rbp), %rdx
	leaq	-400040(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-400040(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -400040(%rbp)
	movl	-400036(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -400036(%rbp)
	movl	-400036(%rbp), %edx
	movl	-400040(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	merge
	addl	$1, -400028(%rbp)
.L11:
	movl	M(%rip), %eax
	cmpl	%eax, -400028(%rbp)
	jl	.L12
	movl	$-1, -400024(%rbp)
	movl	$0, -400020(%rbp)
	jmp	.L13
.L15:
	movl	-400020(%rbp), %eax
	movl	%eax, %edi
	call	root
	movl	%eax, %edx
	movslq	%edx, %rax
	movl	-400016(%rbp,%rax,4), %eax
	leal	1(%rax), %ecx
	movslq	%edx, %rdx
	movl	%ecx, -400016(%rbp,%rdx,4)
	testl	%eax, %eax
	jne	.L14
	addl	$1, -400024(%rbp)
.L14:
	addl	$1, -400020(%rbp)
.L13:
	movl	N(%rip), %eax
	cmpl	%eax, -400020(%rbp)
	jl	.L15
	movl	-400024(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
user
	.file	"temp.c"
	.text
	.p2align 4
	.globl	root
	.type	root, @function
root:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movslq	%edi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	V(%rip), %rbx
	movq	%rbp, %rax
	movl	(%rbx,%rbp,4), %edx
	cmpl	$-1, %edx
	jne	.L21
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L21:
	.cfi_restore_state
	movslq	%edx, %r12
	movl	(%rbx,%r12,4), %ecx
	cmpl	$-1, %ecx
	je	.L3
	movslq	%ecx, %r13
	movl	(%rbx,%r13,4), %eax
	cmpl	$-1, %eax
	jne	.L22
.L4:
	movl	%ecx, (%rbx,%r12,4)
	movl	%ecx, %edx
.L3:
	movl	%edx, (%rbx,%rbp,4)
	movl	%edx, %eax
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L22:
	.cfi_restore_state
	movslq	%eax, %r14
	movl	(%rbx,%r14,4), %edi
	cmpl	$-1, %edi
	je	.L5
	call	root
	movl	%eax, (%rbx,%r14,4)
.L5:
	movl	%eax, (%rbx,%r13,4)
	movl	%eax, %ecx
	jmp	.L4
	.cfi_endproc
.LFE23:
	.size	root, .-root
	.p2align 4
	.globl	merge
	.type	merge, @function
merge:
.LFB24:
	.cfi_startproc
	endbr64
	movslq	%edi, %r9
	leaq	V(%rip), %r10
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	(%r10,%r9,4), %eax
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%r9, %r8
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	cmpl	$-1, %eax
	jne	.L91
	movslq	%esi, %r9
	movl	(%r10,%r9,4), %eax
	cmpl	$-1, %eax
	jne	.L92
.L32:
	cmpl	%r8d, %esi
	je	.L23
	movl	%esi, (%r10,%r8,4)
.L23:
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L91:
	.cfi_restore_state
	movslq	%eax, %r8
	movl	(%r10,%r8,4), %edx
	cmpl	$-1, %edx
	je	.L25
	movslq	%edx, %r11
	movl	(%r10,%r11,4), %eax
	cmpl	$-1, %eax
	jne	.L93
.L26:
	movl	%edx, (%r10,%r8,4)
	movl	%edx, %eax
.L25:
	movl	%eax, (%r10,%r9,4)
	movslq	%esi, %r9
	movslq	%eax, %r8
	movl	(%r10,%r9,4), %eax
	cmpl	$-1, %eax
	je	.L32
.L92:
	movslq	%eax, %rsi
	movl	(%r10,%rsi,4), %edx
	cmpl	$-1, %edx
	je	.L33
	movslq	%edx, %r11
	movl	(%r10,%r11,4), %eax
	cmpl	$-1, %eax
	jne	.L94
.L34:
	movl	%edx, (%r10,%rsi,4)
	movl	%edx, %eax
.L33:
	movl	%eax, (%r10,%r9,4)
	movl	%eax, %esi
	jmp	.L32
	.p2align 4,,10
	.p2align 3
.L94:
	movslq	%eax, %rbx
	movl	(%r10,%rbx,4), %edx
	cmpl	$-1, %edx
	je	.L35
	movslq	%edx, %rbp
	movl	(%r10,%rbp,4), %eax
	cmpl	$-1, %eax
	jne	.L95
.L36:
	movl	%edx, (%r10,%rbx,4)
	movl	%edx, %eax
.L35:
	movl	%eax, (%r10,%r11,4)
	movl	%eax, %edx
	jmp	.L34
	.p2align 4,,10
	.p2align 3
.L93:
	movslq	%eax, %rbx
	movl	(%r10,%rbx,4), %edx
	cmpl	$-1, %edx
	je	.L27
	movslq	%edx, %rbp
	movl	(%r10,%rbp,4), %eax
	cmpl	$-1, %eax
	jne	.L96
.L28:
	movl	%edx, (%r10,%rbx,4)
	movl	%edx, %eax
.L27:
	movl	%eax, (%r10,%r11,4)
	movl	%eax, %edx
	jmp	.L26
	.p2align 4,,10
	.p2align 3
.L96:
	movslq	%eax, %r12
	movl	(%r10,%r12,4), %edx
	cmpl	$-1, %edx
	je	.L29
	movslq	%edx, %r13
	movl	(%r10,%r13,4), %eax
	cmpl	$-1, %eax
	je	.L30
	movslq	%eax, %r14
	movl	(%r10,%r14,4), %edi
	cmpl	$-1, %edi
	je	.L31
	call	root
	movl	%eax, (%r10,%r14,4)
.L31:
	movl	%eax, (%r10,%r13,4)
	movl	%eax, %edx
.L30:
	movl	%edx, (%r10,%r12,4)
	movl	%edx, %eax
.L29:
	movl	%eax, (%r10,%rbp,4)
	movl	%eax, %edx
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L95:
	movslq	%eax, %r12
	movl	(%r10,%r12,4), %edx
	cmpl	$-1, %edx
	je	.L37
	movslq	%edx, %r13
	movl	(%r10,%r13,4), %eax
	cmpl	$-1, %eax
	je	.L38
	movslq	%eax, %r14
	movl	(%r10,%r14,4), %edi
	cmpl	$-1, %edi
	je	.L39
	call	root
	movl	%eax, (%r10,%r14,4)
.L39:
	movl	%eax, (%r10,%r13,4)
	movl	%eax, %edx
.L38:
	movl	%edx, (%r10,%r12,4)
	movl	%edx, %eax
.L37:
	movl	%eax, (%r10,%rbp,4)
	movl	%eax, %edx
	jmp	.L36
	.cfi_endproc
.LFE24:
	.size	merge, .-merge
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB25:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-397312(%rsp), %r11
	.cfi_def_cfa 11, 397368
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2760, %rsp
	.cfi_def_cfa_offset 400128
	movl	$400000, %edx
	xorl	%esi, %esi
	leaq	.LC0(%rip), %r12
	movq	%fs:40, %rax
	movq	%rax, 400056(%rsp)
	xorl	%eax, %eax
	leaq	48(%rsp), %rdi
	call	memset@PLT
	leaq	M(%rip), %rdx
	leaq	N(%rip), %rsi
	xorl	%eax, %eax
	movq	%r12, %rdi
	call	__isoc99_scanf@PLT
	movslq	N(%rip), %rdx
	testl	%edx, %edx
	jle	.L98
	leaq	V(%rip), %rbx
	salq	$2, %rdx
	movl	$255, %esi
	movq	%rbx, %rdi
	call	memset@PLT
	movl	M(%rip), %edx
	testl	%edx, %edx
	jle	.L99
.L135:
	xorl	%ebp, %ebp
	leaq	44(%rsp), %r14
	leaq	40(%rsp), %r13
	.p2align 4,,10
	.p2align 3
.L121:
	movq	%r13, %rsi
	movq	%r14, %rdx
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	40(%rsp), %eax
	leal	-1(%rax), %r9d
	movl	44(%rsp), %eax
	movslq	%r9d, %r8
	movl	%r9d, 40(%rsp)
	leal	-1(%rax), %esi
	movl	(%rbx,%r8,4), %eax
	movl	%esi, 44(%rsp)
	cmpl	$-1, %eax
	je	.L100
	movslq	%eax, %r9
	movl	(%rbx,%r9,4), %edx
	cmpl	$-1, %edx
	je	.L101
	movslq	%edx, %r10
	movl	(%rbx,%r10,4), %eax
	cmpl	$-1, %eax
	je	.L102
	movslq	%eax, %r11
	movl	(%rbx,%r11,4), %edx
	cmpl	$-1, %edx
	jne	.L222
.L103:
	movl	%eax, (%rbx,%r10,4)
	movl	%eax, %edx
.L102:
	movl	%edx, (%rbx,%r9,4)
	movl	%edx, %eax
.L101:
	movl	%eax, (%rbx,%r8,4)
	movl	%eax, %r9d
.L100:
	movslq	%esi, %r8
	movl	(%rbx,%r8,4), %eax
	cmpl	$-1, %eax
	je	.L109
	movslq	%eax, %rsi
	movl	(%rbx,%rsi,4), %edx
	cmpl	$-1, %edx
	je	.L110
	movslq	%edx, %r10
	movl	(%rbx,%r10,4), %eax
	cmpl	$-1, %eax
	je	.L111
	movslq	%eax, %r11
	movl	(%rbx,%r11,4), %edx
	cmpl	$-1, %edx
	jne	.L223
.L112:
	movl	%eax, (%rbx,%r10,4)
	movl	%eax, %edx
.L111:
	movl	%edx, (%rbx,%rsi,4)
	movl	%edx, %eax
.L110:
	movl	%eax, (%rbx,%r8,4)
	movl	%eax, %esi
.L109:
	cmpl	%r9d, %esi
	je	.L118
	movslq	%r9d, %r9
	addl	$1, %ebp
	cmpl	%ebp, M(%rip)
	movl	%esi, (%rbx,%r9,4)
	jg	.L121
.L120:
	movl	N(%rip), %eax
	testl	%eax, %eax
	jle	.L122
.L99:
	xorl	%esi, %esi
	movl	$-1, %r8d
	.p2align 4,,10
	.p2align 3
.L133:
	movl	(%rbx,%rsi,4), %edx
	movslq	%esi, %rax
	cmpl	$-1, %edx
	je	.L123
	movslq	%edx, %r9
	movl	(%rbx,%r9,4), %eax
	cmpl	$-1, %eax
	je	.L124
	movslq	%eax, %r10
	movl	(%rbx,%r10,4), %edx
	cmpl	$-1, %edx
	je	.L125
	movslq	%edx, %r11
	movl	(%rbx,%r11,4), %eax
	cmpl	$-1, %eax
	jne	.L224
.L126:
	movl	%edx, (%rbx,%r10,4)
	movl	%edx, %eax
.L125:
	movl	%eax, (%rbx,%r9,4)
	movl	%eax, %edx
.L124:
	movl	%edx, (%rbx,%rsi,4)
	movslq	%edx, %rax
.L123:
	movl	48(%rsp,%rax,4), %edx
	cmpl	$1, %edx
	leal	1(%rdx), %ecx
	adcl	$0, %r8d
	addq	$1, %rsi
	cmpl	%esi, N(%rip)
	movl	%ecx, 48(%rsp,%rax,4)
	jg	.L133
.L134:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	400056(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L225
	addq	$400072, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L118:
	.cfi_restore_state
	addl	$1, %ebp
	cmpl	%ebp, M(%rip)
	jg	.L121
	jmp	.L120
.L224:
	movslq	%eax, %rbp
	movl	(%rbx,%rbp,4), %edx
	cmpl	$-1, %edx
	je	.L127
	movslq	%edx, %r12
	movl	(%rbx,%r12,4), %eax
	cmpl	$-1, %eax
	jne	.L226
.L128:
	movl	%edx, (%rbx,%rbp,4)
	movl	%edx, %eax
.L127:
	movl	%eax, (%rbx,%r11,4)
	movl	%eax, %edx
	jmp	.L126
.L223:
	movslq	%edx, %r15
	movl	(%rbx,%r15,4), %eax
	cmpl	$-1, %eax
	je	.L113
	movslq	%eax, %rdx
	movl	(%rbx,%rdx,4), %edi
	cmpl	$-1, %edi
	jne	.L227
.L114:
	movl	%eax, (%rbx,%r15,4)
	movl	%eax, %edx
.L113:
	movl	%edx, (%rbx,%r11,4)
	movl	%edx, %eax
	jmp	.L112
.L222:
	movslq	%edx, %r15
	movl	(%rbx,%r15,4), %eax
	cmpl	$-1, %eax
	je	.L104
	movslq	%eax, %rdx
	movl	(%rbx,%rdx,4), %edi
	cmpl	$-1, %edi
	jne	.L228
.L105:
	movl	%eax, (%rbx,%r15,4)
	movl	%eax, %edx
.L104:
	movl	%edx, (%rbx,%r11,4)
	movl	%edx, %eax
	jmp	.L103
.L228:
	movslq	%edi, %rcx
	movl	(%rbx,%rcx,4), %eax
	cmpl	$-1, %eax
	je	.L106
	movslq	%eax, %rdi
	movq	%rdi, (%rsp)
	movl	(%rbx,%rdi,4), %edi
	cmpl	$-1, %edi
	jne	.L229
.L107:
	movl	%eax, (%rbx,%rcx,4)
	movl	%eax, %edi
.L106:
	movl	%edi, (%rbx,%rdx,4)
	movl	%edi, %eax
	jmp	.L105
.L227:
	movslq	%edi, %rcx
	movl	(%rbx,%rcx,4), %eax
	cmpl	$-1, %eax
	je	.L115
	movslq	%eax, %rdi
	movq	%rdi, (%rsp)
	movl	(%rbx,%rdi,4), %edi
	cmpl	$-1, %edi
	jne	.L230
.L116:
	movl	%eax, (%rbx,%rcx,4)
	movl	%eax, %edi
.L115:
	movl	%edi, (%rbx,%rdx,4)
	movl	%edi, %eax
	jmp	.L114
.L226:
	movslq	%eax, %r13
	movl	(%rbx,%r13,4), %edx
	cmpl	$-1, %edx
	je	.L129
	movslq	%edx, %r14
	movl	(%rbx,%r14,4), %eax
	cmpl	$-1, %eax
	jne	.L231
.L130:
	movl	%edx, (%rbx,%r13,4)
	movl	%edx, %eax
.L129:
	movl	%eax, (%rbx,%r12,4)
	movl	%eax, %edx
	jmp	.L128
.L98:
	cmpl	$0, M(%rip)
	leaq	V(%rip), %rbx
	jg	.L135
.L122:
	orl	$-1, %r8d
	jmp	.L134
.L231:
	movslq	%eax, %r15
	movl	(%rbx,%r15,4), %edi
	cmpl	$-1, %edi
	je	.L131
	call	root
	movl	%eax, (%rbx,%r15,4)
.L131:
	movl	%eax, (%rbx,%r14,4)
	movl	%eax, %edx
	jmp	.L130
.L230:
	movslq	%edi, %rax
	movq	%rax, 8(%rsp)
	movl	(%rbx,%rax,4), %eax
	cmpl	$-1, %eax
	je	.L117
	movl	%eax, %edi
	movq	%rcx, 24(%rsp)
	movq	%rdx, 16(%rsp)
	call	root
	movq	24(%rsp), %rcx
	movq	16(%rsp), %rdx
	movl	%eax, %edi
	movq	8(%rsp), %rax
	movl	%edi, (%rbx,%rax,4)
.L117:
	movq	(%rsp), %rax
	movl	%edi, (%rbx,%rax,4)
	movl	%edi, %eax
	jmp	.L116
.L229:
	movslq	%edi, %rax
	movq	%rax, 8(%rsp)
	movl	(%rbx,%rax,4), %eax
	cmpl	$-1, %eax
	je	.L108
	movl	%eax, %edi
	movq	%rcx, 24(%rsp)
	movq	%rdx, 16(%rsp)
	call	root
	movq	24(%rsp), %rcx
	movq	16(%rsp), %rdx
	movl	%eax, %edi
	movq	8(%rsp), %rax
	movl	%edi, (%rbx,%rax,4)
.L108:
	movq	(%rsp), %rax
	movl	%edi, (%rbx,%rax,4)
	movl	%edi, %eax
	jmp	.L107
.L225:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE25:
	.size	main, .-main
	.globl	V
	.bss
	.align 32
	.type	V, @object
	.size	V, 400000
V:
	.zero	400000
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	N
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

rule
	.file	"temp.c"
	.text
	.p2align 4
	.globl	root
	.type	root, @function
root:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movslq	%edi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	V(%rip), %rbx
	movq	%rbp, %rax
	movl	(%rbx,%rbp,4), %edx
	cmpl	$-1, %edx
	jne	.L21
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L21:
	.cfi_restore_state
	movslq	%edx, %r12
	movl	(%rbx,%r12,4), %ecx
	cmpl	$-1, %ecx
	je	.L3
	movslq	%ecx, %r13
	movl	(%rbx,%r13,4), %eax
	cmpl	$-1, %eax
	jne	.L22
.L4:
	movl	%ecx, (%rbx,%r12,4)
	movl	%ecx, %edx
.L3:
	movl	%edx, (%rbx,%rbp,4)
	movl	%edx, %eax
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L22:
	.cfi_restore_state
	movslq	%eax, %r14
	movl	(%rbx,%r14,4), %edi
	cmpl	$-1, %edi
	je	.L5
	call	root
	movl	%eax, (%rbx,%r14,4)
.L5:
	movl	%eax, (%rbx,%r13,4)
	movl	%eax, %ecx
	jmp	.L4
	.cfi_endproc
.LFE23:
	.size	root, .-root
	.p2align 4
	.globl	merge
	.type	merge, @function
merge:
.LFB24:
	.cfi_startproc
	endbr64
	movslq	%edi, %r9
	leaq	V(%rip), %r10
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	(%r10,%r9,4), %eax
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%r9, %r8
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	cmpl	$-1, %eax
	jne	.L91
	movslq	%esi, %r9
	movl	(%r10,%r9,4), %eax
	cmpl	$-1, %eax
	jne	.L92
.L32:
	cmpl	%r8d, %esi
	je	.L23
	movl	%esi, (%r10,%r8,4)
.L23:
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L91:
	.cfi_restore_state
	movslq	%eax, %r8
	movl	(%r10,%r8,4), %edx
	cmpl	$-1, %edx
	je	.L25
	movslq	%edx, %r11
	movl	(%r10,%r11,4), %eax
	cmpl	$-1, %eax
	jne	.L93
.L26:
	movl	%edx, (%r10,%r8,4)
	movl	%edx, %eax
.L25:
	movl	%eax, (%r10,%r9,4)
	movslq	%esi, %r9
	movslq	%eax, %r8
	movl	(%r10,%r9,4), %eax
	cmpl	$-1, %eax
	je	.L32
.L92:
	movslq	%eax, %rsi
	movl	(%r10,%rsi,4), %edx
	cmpl	$-1, %edx
	je	.L33
	movslq	%edx, %r11
	movl	(%r10,%r11,4), %eax
	cmpl	$-1, %eax
	jne	.L94
.L34:
	movl	%edx, (%r10,%rsi,4)
	movl	%edx, %eax
.L33:
	movl	%eax, (%r10,%r9,4)
	movl	%eax, %esi
	jmp	.L32
	.p2align 4,,10
	.p2align 3
.L94:
	movslq	%eax, %rbx
	movl	(%r10,%rbx,4), %edx
	cmpl	$-1, %edx
	je	.L35
	movslq	%edx, %rbp
	movl	(%r10,%rbp,4), %eax
	cmpl	$-1, %eax
	jne	.L95
.L36:
	movl	%edx, (%r10,%rbx,4)
	movl	%edx, %eax
.L35:
	movl	%eax, (%r10,%r11,4)
	movl	%eax, %edx
	jmp	.L34
	.p2align 4,,10
	.p2align 3
.L93:
	movslq	%eax, %rbx
	movl	(%r10,%rbx,4), %edx
	cmpl	$-1, %edx
	je	.L27
	movslq	%edx, %rbp
	movl	(%r10,%rbp,4), %eax
	cmpl	$-1, %eax
	jne	.L96
.L28:
	movl	%edx, (%r10,%rbx,4)
	movl	%edx, %eax
.L27:
	movl	%eax, (%r10,%r11,4)
	movl	%eax, %edx
	jmp	.L26
	.p2align 4,,10
	.p2align 3
.L96:
	movslq	%eax, %r12
	movl	(%r10,%r12,4), %edx
	cmpl	$-1, %edx
	je	.L29
	movslq	%edx, %r13
	movl	(%r10,%r13,4), %eax
	cmpl	$-1, %eax
	je	.L30
	movslq	%eax, %r14
	movl	(%r10,%r14,4), %edi
	cmpl	$-1, %edi
	je	.L31
	call	root
	movl	%eax, (%r10,%r14,4)
.L31:
	movl	%eax, (%r10,%r13,4)
	movl	%eax, %edx
.L30:
	movl	%edx, (%r10,%r12,4)
	movl	%edx, %eax
.L29:
	movl	%eax, (%r10,%rbp,4)
	movl	%eax, %edx
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L95:
	movslq	%eax, %r12
	movl	(%r10,%r12,4), %edx
	cmpl	$-1, %edx
	je	.L37
	movslq	%edx, %r13
	movl	(%r10,%r13,4), %eax
	cmpl	$-1, %eax
	je	.L38
	movslq	%eax, %r14
	movl	(%r10,%r14,4), %edi
	cmpl	$-1, %edi
	je	.L39
	call	root
	movl	%eax, (%r10,%r14,4)
.L39:
	movl	%eax, (%r10,%r13,4)
	movl	%eax, %edx
.L38:
	movl	%edx, (%r10,%r12,4)
	movl	%edx, %eax
.L37:
	movl	%eax, (%r10,%rbp,4)
	movl	%eax, %edx
	jmp	.L36
	.cfi_endproc
.LFE24:
	.size	merge, .-merge
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB25:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-397312(%rsp), %r11
	.cfi_def_cfa 11, 397368
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2760, %rsp
	.cfi_def_cfa_offset 400128
	movl	$400000, %edx
	xorl	%esi, %esi
	leaq	.LC0(%rip), %r12
	movq	%fs:40, %rax
	movq	%rax, 400056(%rsp)
	xorl	%eax, %eax
	leaq	48(%rsp), %rdi
	call	memset@PLT
	leaq	M(%rip), %rdx
	leaq	N(%rip), %rsi
	xorl	%eax, %eax
	movq	%r12, %rdi
	call	__isoc99_scanf@PLT
	movslq	N(%rip), %rdx
	testl	%edx, %edx
	jle	.L98
	leaq	V(%rip), %rbx
	salq	$2, %rdx
	movl	$255, %esi
	movq	%rbx, %rdi
	call	memset@PLT
	movl	M(%rip), %edx
	testl	%edx, %edx
	jle	.L99
.L135:
	xorl	%ebp, %ebp
	leaq	44(%rsp), %r14
	leaq	40(%rsp), %r13
	.p2align 4,,10
	.p2align 3
.L121:
	movq	%r13, %rsi
	movq	%r14, %rdx
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	40(%rsp), %eax
	leal	-1(%rax), %r9d
	movl	44(%rsp), %eax
	movslq	%r9d, %r8
	movl	%r9d, 40(%rsp)
	leal	-1(%rax), %esi
	movl	(%rbx,%r8,4), %eax
	movl	%esi, 44(%rsp)
	cmpl	$-1, %eax
	je	.L100
	movslq	%eax, %r9
	movl	(%rbx,%r9,4), %edx
	cmpl	$-1, %edx
	je	.L101
	movslq	%edx, %r10
	movl	(%rbx,%r10,4), %eax
	cmpl	$-1, %eax
	je	.L102
	movslq	%eax, %r11
	movl	(%rbx,%r11,4), %edx
	cmpl	$-1, %edx
	jne	.L222
.L103:
	movl	%eax, (%rbx,%r10,4)
	movl	%eax, %edx
.L102:
	movl	%edx, (%rbx,%r9,4)
	movl	%edx, %eax
.L101:
	movl	%eax, (%rbx,%r8,4)
	movl	%eax, %r9d
.L100:
	movslq	%esi, %r8
	movl	(%rbx,%r8,4), %eax
	cmpl	$-1, %eax
	je	.L109
	movslq	%eax, %rsi
	movl	(%rbx,%rsi,4), %edx
	cmpl	$-1, %edx
	je	.L110
	movslq	%edx, %r10
	movl	(%rbx,%r10,4), %eax
	cmpl	$-1, %eax
	je	.L111
	movslq	%eax, %r11
	movl	(%rbx,%r11,4), %edx
	cmpl	$-1, %edx
	jne	.L223
.L112:
	movl	%eax, (%rbx,%r10,4)
	movl	%eax, %edx
.L111:
	movl	%edx, (%rbx,%rsi,4)
	movl	%edx, %eax
.L110:
	movl	%eax, (%rbx,%r8,4)
	movl	%eax, %esi
.L109:
	cmpl	%r9d, %esi
	je	.L118
	movslq	%r9d, %r9
	addl	$1, %ebp
	cmpl	%ebp, M(%rip)
	movl	%esi, (%rbx,%r9,4)
	jg	.L121
.L120:
	movl	N(%rip), %eax
	testl	%eax, %eax
	jle	.L122
.L99:
	xorl	%esi, %esi
	movl	$-1, %r8d
	.p2align 4,,10
	.p2align 3
.L133:
	movl	(%rbx,%rsi,4), %edx
	movslq	%esi, %rax
	cmpl	$-1, %edx
	je	.L123
	movslq	%edx, %r9
	movl	(%rbx,%r9,4), %eax
	cmpl	$-1, %eax
	je	.L124
	movslq	%eax, %r10
	movl	(%rbx,%r10,4), %edx
	cmpl	$-1, %edx
	je	.L125
	movslq	%edx, %r11
	movl	(%rbx,%r11,4), %eax
	cmpl	$-1, %eax
	jne	.L224
.L126:
	movl	%edx, (%rbx,%r10,4)
	movl	%edx, %eax
.L125:
	movl	%eax, (%rbx,%r9,4)
	movl	%eax, %edx
.L124:
	movl	%edx, (%rbx,%rsi,4)
	movslq	%edx, %rax
.L123:
	movl	48(%rsp,%rax,4), %edx
	cmpl	$1, %edx
	leal	1(%rdx), %ecx
	adcl	$0, %r8d
	addq	$1, %rsi
	cmpl	%esi, N(%rip)
	movl	%ecx, 48(%rsp,%rax,4)
	jg	.L133
.L134:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	400056(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L225
	addq	$400072, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L118:
	.cfi_restore_state
	addl	$1, %ebp
	cmpl	%ebp, M(%rip)
	jg	.L121
	jmp	.L120
.L224:
	movslq	%eax, %rbp
	movl	(%rbx,%rbp,4), %edx
	cmpl	$-1, %edx
	je	.L127
	movslq	%edx, %r12
	movl	(%rbx,%r12,4), %eax
	cmpl	$-1, %eax
	jne	.L226
.L128:
	movl	%edx, (%rbx,%rbp,4)
	movl	%edx, %eax
.L127:
	movl	%eax, (%rbx,%r11,4)
	movl	%eax, %edx
	jmp	.L126
.L223:
	movslq	%edx, %r15
	movl	(%rbx,%r15,4), %eax
	cmpl	$-1, %eax
	je	.L113
	movslq	%eax, %rdx
	movl	(%rbx,%rdx,4), %edi
	cmpl	$-1, %edi
	jne	.L227
.L114:
	movl	%eax, (%rbx,%r15,4)
	movl	%eax, %edx
.L113:
	movl	%edx, (%rbx,%r11,4)
	movl	%edx, %eax
	jmp	.L112
.L222:
	movslq	%edx, %r15
	movl	(%rbx,%r15,4), %eax
	cmpl	$-1, %eax
	je	.L104
	movslq	%eax, %rdx
	movl	(%rbx,%rdx,4), %edi
	cmpl	$-1, %edi
	jne	.L228
.L105:
	movl	%eax, (%rbx,%r15,4)
	movl	%eax, %edx
.L104:
	movl	%edx, (%rbx,%r11,4)
	movl	%edx, %eax
	jmp	.L103
.L228:
	movslq	%edi, %rcx
	movl	(%rbx,%rcx,4), %eax
	cmpl	$-1, %eax
	je	.L106
	movslq	%eax, %rdi
	movq	%rdi, (%rsp)
	movl	(%rbx,%rdi,4), %edi
	cmpl	$-1, %edi
	jne	.L229
.L107:
	movl	%eax, (%rbx,%rcx,4)
	movl	%eax, %edi
.L106:
	movl	%edi, (%rbx,%rdx,4)
	movl	%edi, %eax
	jmp	.L105
.L227:
	movslq	%edi, %rcx
	movl	(%rbx,%rcx,4), %eax
	cmpl	$-1, %eax
	je	.L115
	movslq	%eax, %rdi
	movq	%rdi, (%rsp)
	movl	(%rbx,%rdi,4), %edi
	cmpl	$-1, %edi
	jne	.L230
.L116:
	movl	%eax, (%rbx,%rcx,4)
	movl	%eax, %edi
.L115:
	movl	%edi, (%rbx,%rdx,4)
	movl	%edi, %eax
	jmp	.L114
.L226:
	movslq	%eax, %r13
	movl	(%rbx,%r13,4), %edx
	cmpl	$-1, %edx
	je	.L129
	movslq	%edx, %r14
	movl	(%rbx,%r14,4), %eax
	cmpl	$-1, %eax
	jne	.L231
.L130:
	movl	%edx, (%rbx,%r13,4)
	movl	%edx, %eax
.L129:
	movl	%eax, (%rbx,%r12,4)
	movl	%eax, %edx
	jmp	.L128
.L98:
	cmpl	$0, M(%rip)
	leaq	V(%rip), %rbx
	jg	.L135
.L122:
	orl	$-1, %r8d
	jmp	.L134
.L231:
	movslq	%eax, %r15
	movl	(%rbx,%r15,4), %edi
	cmpl	$-1, %edi
	je	.L131
	call	root
	movl	%eax, (%rbx,%r15,4)
.L131:
	movl	%eax, (%rbx,%r14,4)
	movl	%eax, %edx
	jmp	.L130
.L230:
	movslq	%edi, %rax
	movq	%rax, 8(%rsp)
	movl	(%rbx,%rax,4), %eax
	cmpl	$-1, %eax
	je	.L117
	movl	%eax, %edi
	movq	%rcx, 24(%rsp)
	movq	%rdx, 16(%rsp)
	call	root
	movq	24(%rsp), %rcx
	movq	16(%rsp), %rdx
	movl	%eax, %edi
	movq	8(%rsp), %rax
	movl	%edi, (%rbx,%rax,4)
.L117:
	movq	(%rsp), %rax
	movl	%edi, (%rbx,%rax,4)
	movl	%edi, %eax
	jmp	.L116
.L229:
	movslq	%edi, %rax
	movq	%rax, 8(%rsp)
	movl	(%rbx,%rax,4), %eax
	cmpl	$-1, %eax
	je	.L108
	movl	%eax, %edi
	movq	%rcx, 24(%rsp)
	movq	%rdx, 16(%rsp)
	call	root
	movq	24(%rsp), %rcx
	movq	16(%rsp), %rdx
	movl	%eax, %edi
	movq	8(%rsp), %rax
	movl	%edi, (%rbx,%rax,4)
.L108:
	movq	(%rsp), %rax
	movl	%edi, (%rbx,%rax,4)
	movl	%edi, %eax
	jmp	.L107
.L225:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE25:
	.size	main, .-main
	.globl	V
	.bss
	.align 32
	.type	V, @object
	.size	V, 400000
V:
	.zero	400000
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	N
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include<stdio.h>

int N, M;
int V[100000];

int root(int x) {
  if(V[x] == -1) return x;
  else return V[x] = root(V[x]);
}

void merge(int a, int b) {
  a = root(a);
  b = root(b);
  if(a == b) return;
  V[a] = b;
}

int main() {
  int unique[100000] = {};
  scanf("%d%d", &N, &M);
  for(int i = 0;i < N;i++) V[i] = -1;
  for(int i = 0;i < M;i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--; b--;
    merge(a, b);
  }
  int ans = -1;
  for(int i = 0;i < N;i++) {
    if(unique[root(i)]++ == 0) ans++;
  }
  printf("%d\n", ans);
}

3 1
1 1
 5 1
1 1
 6 1
1 1
 3 1
3 2
 5 1
3 2
 2 1
1 2
 9 1
1 2
 15 1
1 2
 10 1
1 2
 10 1
1 1

2
 4
 5
 1
 3
 0
 7
 13
 8
 9

Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include<stdio.h>

int N, M;
int V[100000];

int root(int x) {
  if(V[x] == -1) return x;
  else return V[x] = root(V[x]);
}

void merge(int a, int b) {
  a = root(a);
  b = root(b);
  if(a == b) return;
  V[a] = b;
}

int main() {
  int unique[100000] = {};
  scanf("%d%d", &N, &M);
  for(int i = 0;i < N;i++) V[i] = -1;
  for(int i = 0;i < M;i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--; b--;
    merge(a, b);
  }
  int ans = -1;
  for(int i = 0;i < N;i++) {
    if(unique[root(i)]++ == 0) ans++;
  }
  printf("%d\n", ans);
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	N
	.bss
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	V
	.align 32
	.type	V, @object
	.size	V, 400000
V:
	.zero	400000
	.text
	.globl	root
	.type	root, @function
root:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	V(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	jne	.L2
	movl	-4(%rbp), %eax
	jmp	.L3
.L2:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	V(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %edi
	call	root
	movl	-4(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	V(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	V(%rip), %rax
	movl	(%rdx,%rax), %eax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	root, .-root
	.globl	merge
	.type	merge, @function
merge:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, %edi
	call	root
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, %edi
	call	root
	movl	%eax, -8(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-8(%rbp), %eax
	je	.L7
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	V(%rip), %rdx
	movl	-8(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	jmp	.L4
.L7:
	nop
.L4:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	merge, .-merge
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-397312(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2736, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-400016(%rbp), %rax
	movl	$400000, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	M(%rip), %rax
	movq	%rax, %rdx
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -400032(%rbp)
	jmp	.L9
.L10:
	movl	-400032(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	V(%rip), %rax
	movl	$-1, (%rdx,%rax)
	addl	$1, -400032(%rbp)
.L9:
	movl	N(%rip), %eax
	cmpl	%eax, -400032(%rbp)
	jl	.L10
	movl	$0, -400028(%rbp)
	jmp	.L11
.L12:
	leaq	-400036(%rbp), %rdx
	leaq	-400040(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-400040(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -400040(%rbp)
	movl	-400036(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -400036(%rbp)
	movl	-400036(%rbp), %edx
	movl	-400040(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	merge
	addl	$1, -400028(%rbp)
.L11:
	movl	M(%rip), %eax
	cmpl	%eax, -400028(%rbp)
	jl	.L12
	movl	$-1, -400024(%rbp)
	movl	$0, -400020(%rbp)
	jmp	.L13
.L15:
	movl	-400020(%rbp), %eax
	movl	%eax, %edi
	call	root
	movl	%eax, %edx
	movslq	%edx, %rax
	movl	-400016(%rbp,%rax,4), %eax
	leal	1(%rax), %ecx
	movslq	%edx, %rdx
	movl	%ecx, -400016(%rbp,%rdx,4)
	testl	%eax, %eax
	jne	.L14
	addl	$1, -400024(%rbp)
.L14:
	addl	$1, -400020(%rbp)
.L13:
	movl	N(%rip), %eax
	cmpl	%eax, -400020(%rbp)
	jl	.L15
	movl	-400024(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
train
	.file	"temp.c"
	.text
	.globl	N
	.bss
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	V
	.align 32
	.type	V, @object
	.size	V, 400000
V:
	.zero	400000
	.text
	.globl	root
	.type	root, @function
root:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	V(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	jne	.L2
	movl	-4(%rbp), %eax
	jmp	.L3
.L2:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	V(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %edi
	call	root
	movl	-4(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	V(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	V(%rip), %rax
	movl	(%rdx,%rax), %eax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	root, .-root
	.globl	merge
	.type	merge, @function
merge:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, %edi
	call	root
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, %edi
	call	root
	movl	%eax, -8(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-8(%rbp), %eax
	je	.L7
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	V(%rip), %rdx
	movl	-8(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	jmp	.L4
.L7:
	nop
.L4:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	merge, .-merge
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-397312(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2736, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-400016(%rbp), %rax
	movl	$400000, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	M(%rip), %rax
	movq	%rax, %rdx
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -400032(%rbp)
	jmp	.L9
.L10:
	movl	-400032(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	V(%rip), %rax
	movl	$-1, (%rdx,%rax)
	addl	$1, -400032(%rbp)
.L9:
	movl	N(%rip), %eax
	cmpl	%eax, -400032(%rbp)
	jl	.L10
	movl	$0, -400028(%rbp)
	jmp	.L11
.L12:
	leaq	-400036(%rbp), %rdx
	leaq	-400040(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-400040(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -400040(%rbp)
	movl	-400036(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -400036(%rbp)
	movl	-400036(%rbp), %edx
	movl	-400040(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	merge
	addl	$1, -400028(%rbp)
.L11:
	movl	M(%rip), %eax
	cmpl	%eax, -400028(%rbp)
	jl	.L12
	movl	$-1, -400024(%rbp)
	movl	$0, -400020(%rbp)
	jmp	.L13
.L15:
	movl	-400020(%rbp), %eax
	movl	%eax, %edi
	call	root
	movl	%eax, %edx
	movslq	%edx, %rax
	movl	-400016(%rbp,%rax,4), %eax
	leal	1(%rax), %ecx
	movslq	%edx, %rdx
	movl	%ecx, -400016(%rbp,%rdx,4)
	testl	%eax, %eax
	jne	.L14
	addl	$1, -400024(%rbp)
.L14:
	addl	$1, -400020(%rbp)
.L13:
	movl	N(%rip), %eax
	cmpl	%eax, -400020(%rbp)
	jl	.L15
	movl	-400024(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
