Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# D - Friends
def append_(A, B):
  global people

  people.setdefault(A, [])
  people[A].append(B)


def create_new_group(p):
  global groups

  group = set()
  group.add(p)

  groups.append(group)


def exists_friend(i, group):
  global friends

  for p in group:
    if i in friends[p]:
      return True


N, M = map(int, input().split())
people = dict()

for i in range(M):
  A, B = map(int, input().split())
  append_(A, B)
  append_(B, A)

friends = dict()

for i in range(1, N + 1):
  friends[i] = set()

for k in people:
  for v in people[k]:
    friends[k].add(v)

    for f in people[v]:
      friends[k].add(f)

groups = []
create_new_group(1)

for i in range(2, N + 1):
  is_added = False

  for group in groups:
    if not exists_friend(i, group):
      group.add(i)
      is_added = True
      break

  if not is_added:
    create_new_group(i)

print(len(groups))

#for g in groups:
  #print(g)

Fixed submission:
# D - Friends
def add_to_graph(A, B):
  global graph

  graph.setdefault(A, [])
  graph[A].append(B)


def add_to_group(p):
  global que
  global group
  global is_finished

  que.append(p)
  group.add(p)
  is_finished[p] = True


from collections import deque

N, M = map(int, input().split())
graph = dict()

for i in range(M):
  A, B = map(int, input().split())
  add_to_graph(A, B)
  add_to_graph(B, A)

# その人を探索したかどうかのフラグ
is_finished = [False] * (N + 1)
groups = []

for i in range(1, N + 1):
  que = deque()
  group = set()

  if not is_finished[i]:
    add_to_group(i)

    while len(que) > 0:
      p = que.popleft()
  
      if p in graph.keys():
        for v in graph[p]:
          if not is_finished[v]:
            add_to_group(v)
    
      groups.append(group)

ans = 0

for g in groups:
  ans = max(ans, len(g))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# D - Friends
def append_(A, B):
  global people

  people.setdefault(A, [])
  people[A].append(B)


def create_new_group(p):
  global groups

  group = set()
  group.add(p)

  groups.append(group)


def exists_friend(i, group):
  global friends

  for p in group:
    if i in friends[p]:
      return True


N, M = map(int, input().split())
people = dict()

for i in range(M):
  A, B = map(int, input().split())
  append_(A, B)
  append_(B, A)

friends = dict()

for i in range(1, N + 1):
  friends[i] = set()

for k in people:
  for v in people[k]:
    friends[k].add(v)

    for f in people[v]:
      friends[k].add(f)

groups = []
create_new_group(1)

for i in range(2, N + 1):
  is_added = False

  for group in groups:
    if not exists_friend(i, group):
      group.add(i)
      is_added = True
      break

  if not is_added:
    create_new_group(i)

print(len(groups))

#for g in groups:
  #print(g)

Fixed submission:
# D - Friends
def add_to_graph(A, B):
  global graph

  graph.setdefault(A, [])
  graph[A].append(B)


def add_to_group(p):
  global que
  global group
  global is_finished

  que.append(p)
  group.add(p)
  is_finished[p] = True


from collections import deque

N, M = map(int, input().split())
graph = dict()

for i in range(M):
  A, B = map(int, input().split())
  add_to_graph(A, B)
  add_to_graph(B, A)

# その人を探索したかどうかのフラグ
is_finished = [False] * (N + 1)
groups = []

for i in range(1, N + 1):
  que = deque()
  group = set()

  if not is_finished[i]:
    add_to_group(i)

    while len(que) > 0:
      p = que.popleft()
  
      if p in graph.keys():
        for v in graph[p]:
          if not is_finished[v]:
            add_to_group(v)
    
      groups.append(group)

ans = 0

for g in groups:
  ans = max(ans, len(g))

print(ans)