This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:   Only segments already presented on the picture can be painted;  The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;  The numbers of points from the beginning of the tail to the end should strictly increase. 

Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.

Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.


-----Input-----

First line of the input contains two integers n and m(2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number segments on the picture respectively. 

Then follow m lines, each containing two integers u_{i} and v_{i} (1 ≤ u_{i}, v_{i} ≤ n, u_{i} ≠ v_{i}) — the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.


-----Output-----

Print the maximum possible value of the hedgehog's beauty.


-----Examples-----
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7

Output
9

Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4

Output
12



-----Note-----

The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3·3 = 9.

[Image]

Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Graph algorithms
Skill types: Dynamic programming

Starter code:

Solutions:
(n, m) = [int(x) for x in input().split()]
values = [1] * n
nodes = [list() for _ in range(n)]
spikes = [0] * n
for _ in range(m):
	(n1, n2) = [int(x) for x in input().split()]
	if n1 > n2:
		(n1, n2) = (n2, n1)
	nodes[n1 - 1].append(n2 - 1)
	spikes[n1 - 1] += 1
	spikes[n2 - 1] += 1
for i in range(0, n):
	for node in nodes[i]:
		values[node] = max(values[node], values[i] + 1)
m = max(list(range(n)), key=lambda i: spikes[i] * values[i])
print(spikes[m] * values[m])


(n, m) = list(map(int, input().split()))
p = [0] * n
e = []
for i in range(m):
	(q, w) = list(map(int, input().split()))
	p[w - 1] += 1
	p[q - 1] += 1
	e.append([min(q, w), max(q, w)])
dp = [1] * n
e.sort()
for i in range(m):
	dp[e[i][1] - 1] = max(dp[e[i][1] - 1], dp[e[i][0] - 1] + 1)
ans = 0
for i in range(n):
	ans = max(ans, dp[i] * p[i])
print(ans)


def main():
	(n, m) = list(map(int, input().split()))
	n += 1
	children = [[] for _ in range(n)]
	(degree, depth) = ([0] * n, [1] * n)
	for _ in range(m):
		(u, v) = list(map(int, input().split()))
		if u < v:
			children[u].append(v)
		else:
			children[v].append(u)
		degree[u] += 1
		degree[v] += 1
	for (a, c) in zip(depth, children):
		for v in c:
			if depth[v] <= a:
				depth[v] = a + 1
	print(max((a * b for (a, b) in zip(depth, degree))))

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
edges = []
max_lens = []
for i in range(n + 1):
	edges.append(set())
	max_lens.append(1)
for i in range(m):
	(u, v) = map(int, input().split())
	edges[u].add(v)
	edges[v].add(u)
maximum = 0
for i in range(1, n + 1):
	for j in edges[i]:
		if j < i:
			max_lens[i] = max(max_lens[i], max_lens[j] + 1)
	maximum = max(len(edges[i]) * max_lens[i], maximum)
print(maximum)


from collections import defaultdict
(n, m) = map(int, input().split())
G = defaultdict(list)
for _ in range(m):
	(u, v) = map(int, input().split())
	G[u].append(v)
	G[v].append(u)
rs = [1] * n
for u in range(1, n + 1):
	for v in G[u]:
		if v < u:
			rs[u - 1] = max(rs[u - 1], rs[v - 1] + 1)
print(max((rs[i] * len(G[i + 1]) for i in range(len(rs)))))


import sys
l = 0
ady = [[]]
ady2 = [[]]
for line in sys.stdin:
	if l == 0:
		(n, m) = line.split()
		n = int(n)
		m = int(m)
		ady = [[] for i in range(n)]
		ady2 = [[] for i in range(n)]
	else:
		(a, b) = map(int, line.split())
		a = int(a) - 1
		b = int(b) - 1
		ady2[a].append(b)
		ady2[b].append(a)
		if a > b:
			ady[a].append(b)
		else:
			ady[b].append(a)
	l += 1
c = [0] * n

def colamaslarga(a):
	if len(ady[a]) == 0:
		c[a] = 1
		return 1
	elif c[a] != 0:
		return c[a]
	else:
		res = max([colamaslarga(ad) for ad in ady[a]]) + 1
		c[a] = res
		return res
mx = 0
for i in range(n):
	cl = colamaslarga(i)
	res = cl * len(ady2[i])
	if res > mx:
		mx = res
print(mx)


read = lambda : map(int, input().split())
(n, m) = read()
g = [list() for i in range(n + 1)]
cnt = [0] * (n + 1)
dist = [0] * (n + 1)
for i in range(m):
	(u, v) = read()
	cnt[u] += 1
	cnt[v] += 1
	if u < v:
		(u, v) = (v, u)
	g[u].append(v)
for v in range(1, n + 1):
	res = 1
	for u in g[v]:
		res = max(res, dist[u] + 1)
	dist[v] = res
ans = max((dist[i] * cnt[i] for i in range(1, n + 1)))
print(ans)


(n, m) = map(int, input().split())
A = [[] for _ in range(n + 1)]
B = [0 for _ in range(n + 1)]
for i in range(m):
	(u, v) = map(int, input().split())
	if u > v:
		(u, v) = (v, u)
	A[u].append(v)
	B[u] += 1
	B[v] += 1
C = [0 for _ in range(n + 1)]
X = B[1]
for u in range(1, n + 1):
	for v in A[u]:
		C[v] = max(C[v], C[u] + 1)
		X = max(X, (C[v] + 1) * B[v])
print(X)


(n, m) = [int(x) for x in input().split()]
E = {i: [] for i in range(1, n + 1)}
for i in range(m):
	(u, v) = [int(x) for x in input().split()]
	E[v].append(u)
	E[u].append(v)
tail = {i: 0 for i in range(1, n + 1)}
tail[1] = 1
for u in range(2, n + 1):
	tail[u] = max((tail[v] for v in E[u]), default=0) + 1
print(max((tail[u] * len(E[u]) for u in range(1, n + 1))))


(n, m) = map(int, input().split())
graph = [list() for _ in range(n + 1)]
count = [0 for _ in range(n + 1)]
dp = [0 for _ in range(n + 1)]
for _ in range(m):
	(u, v) = map(int, input().split())
	if v < u:
		(u, v) = (v, u)
	graph[v].append(u)
	count[v] += 1
	count[u] += 1
for i in range(1, n + 1):
	best = 1
	for j in graph[i]:
		best = max(best, dp[j] + 1)
	dp[i] = best
result = 1
for i in range(1, n + 1):
	if dp[i] * count[i] > result:
		result = dp[i] * count[i]
print(result)


from collections import defaultdict as ddict
(n, m) = map(int, input().split())
graph = ddict(set)
for i in range(m):
	(u, v) = map(int, input().split())
	graph[u].add(v)
	graph[v].add(u)
dp = [1] * (n + 1)
for u in graph:
	for v in graph[u]:
		if v > u:
			dp[v] = max(dp[u] + 1, dp[v])
mx = 0
for u in graph:
	mx = max(mx, dp[u] * len(graph[u]))
print(mx)


R = lambda : map(int, input().split())
(n, m) = R()
adj = [[] for _ in range(n)]
from collections import defaultdict
d = defaultdict(int)
for i in range(m):
	(u, v) = R()
	if u > v:
		(u, v) = (v, u)
	adj[u - 1].append(v - 1)
	d[u - 1] += 1
	d[v - 1] += 1
h = defaultdict(int)
for i in range(n):
	h[i] = max(h[i], 1)
	for v in adj[i]:
		h[v] = max(h[v], h[i] + 1)
mx = 0
for i in range(n):
	mx = max(mx, h[i] * d[i])
print(mx)


(n, m) = map(int, input().split())
G = [[] for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
max_dist = 0
dist = [0] * n
for v in range(n):
	dist[v] = 1
	for u in G[v]:
		if u < v:
			dist[v] = max(dist[v], dist[u] + 1)
		max_dist = max(max_dist, dist[v] * len(G[v]))
print(max_dist)


(n, m) = map(int, input().split())
children = [[] for u in range(n + 1)]
degree = [0 for u in range(n + 1)]
for i in range(m):
	(u, v) = map(int, input().split())
	if u > v:
		(u, v) = (v, u)
	children[u].append(v)
	degree[u] += 1
	degree[v] += 1
depth = [0 for u in range(n + 1)]
best = degree[1]
for u in range(1, n + 1):
	for v in children[u]:
		depth[v] = max(depth[v], depth[u] + 1)
		best = max(best, (depth[v] + 1) * degree[v])
print(best)


(n, m) = map(int, input().split())
g = [[] for i in range(n)]
for _ in range(m):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	g[u].append(v)
	g[v].append(u)
dp = [1] * n
for i in range(n):
	for j in g[i]:
		if i < j:
			dp[j] = max(dp[j], dp[i] + 1)
ans = 0
for i in range(n):
	ans = max(ans, len(g[i]) * dp[i])
print(ans)


from sys import stdin, setrecursionlimit
setrecursionlimit(100000)

class Graph:

	def __init__(self, No_of_nodes):
		self.n = No_of_nodes
		self.adj = [[] for i in range(self.n)]

	def addEdge(self, a, b):
		self.adj[a].append(b)
		self.adj[b].append(a)
		count[a][0] += 1
		count[b][0] += 1

def solve(start):
	for i in g.adj[start]:
		if i < start:
			dp[start] = max(dp[start], dp[i] + 1)
	return dp[start]
(n, m) = map(int, stdin.readline().split())
g = Graph(n)
count = [[0, i] for i in range(n)]
dp = [1] * n
for i in range(m):
	(a, b) = map(int, stdin.readline().split())
	a -= 1
	b -= 1
	g.addEdge(a, b)
for i in range(n):
	solve(i)
ans = -1000
for i in range(n):
	if dp[i] != -1:
		ans = max(ans, dp[i] * len(g.adj[i]))
print(ans)


(n, m) = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
	(u, v) = map(int, input().split())
	graph[u - 1].append(v - 1)
	graph[v - 1].append(u - 1)
dp = [1 for _ in range(n)]
for i in range(n):
	for v in graph[i]:
		if v < i:
			dp[i] = max(dp[i], dp[v] + 1)
print(max([dp[i] * len(graph[i]) for i in range(n)]))


def read_list():
	return [int(i) for i in input().split()]

def new_list(n):
	return [0 for i in range(n)]

def new_list_list(n):
	return [[] for i in range(n)]
dp = new_list(100001)
g = new_list_list(100001)
(n, m) = read_list()
for i in range(m):
	(v, u) = read_list()
	g[v].append(u)
	g[u].append(v)
answ = 0
for v in range(1, n + 1):
	dp[v] = 1
	for u in g[v]:
		if u < v:
			dp[v] = max(dp[v], dp[u] + 1)
	answ = max(answ, dp[v] * len(g[v]))
print(answ)


import sys
if False:
	inp = open('B.txt', 'r')
else:
	inp = sys.stdin
data = [[] for i in range(100009)]
spines = [0 for i in range(100009)]
dp = [1 for i in range(100009)]
(n, m) = map(int, inp.readline().split())
for i in range(m):
	(a, b) = map(int, inp.readline().split())
	if a < b:
		data[b].append(a)
	else:
		data[a].append(b)
	spines[a] += 1
	spines[b] += 1
ans = 0
dp[1] = 1
ans = spines[1]
for i in range(2, n + 1):
	ret = 0
	for item in data[i]:
		ret = max(ret, dp[item])
	dp[i] = ret + 1
	ans = max(ans, (ret + 1) * spines[i])
print(ans)


from sys import stdin
a = lambda : stdin.readline().split()
(n, m) = map(int, a())
d = {i: [] for i in range(1, n + 1)}
di = {i: 0 for i in range(1, n + 1)}
for _ in range(m):
	(u, v) = map(int, a())
	if u > v:
		d[u].append(v)
	else:
		d[v].append(u)
	di[u] += 1
	di[v] += 1
res = [1]
result = di[1]
for i in range(2, n + 1):
	item = 0
	for (j, y) in enumerate(d[i]):
		item = max(item, res[y - 1])
	item += 1
	res.append(item)
	result = max(result, item * di[i])
print(result)


(n, m) = map(int, input().split())
g = {x: [] for x in range(1, n + 1)}
dp = [1] * (n + 1)
ans = 0
for _ in range(m):
	(a, b) = map(int, input().split())
	g[a].append(b)
	g[b].append(a)
for v in range(1, n + 1):
	for u in g[v]:
		if u < v:
			dp[v] = max(dp[v], dp[u] + 1)
	ans = max(ans, dp[v] * len(g[v]))
print(ans)


def main():
	(n, m) = [int(t) for t in input().split()]
	tail_length = [0 for _ in range(n)]
	adj_list = [set() for _ in range(n)]
	for _ in range(m):
		(u, v) = [int(t) - 1 for t in input().split()]
		adj_list[u].add(v)
		adj_list[v].add(u)
	tail_length[0] = 1
	beauty = tail_length[0] * len(adj_list[0])
	for u in range(1, n):
		candidate_tail_lengths = [tail_length[v] + 1 for v in adj_list[u] if v < u]
		if len(candidate_tail_lengths) != 0:
			tail_length[u] = max(candidate_tail_lengths)
		else:
			tail_length[u] = 1
		beauty = max(beauty, tail_length[u] * len(adj_list[u]))
	print(beauty)

def __starting_point():
	main()
__starting_point()


from collections import deque

def R():
	return map(int, input().strip().split())
(n, m) = R()
graph = {}
for i in range(m):
	(u, v) = R()
	try:
		graph[u].append(v)
	except:
		graph[u] = [v]
	try:
		graph[v].append(u)
	except:
		graph[v] = [u]
try:
	dp = [1 for i in range(n + 1)]
	for i in range(1, n + 1):
		for j in graph.get(i, []):
			if j > i:
				dp[j] = max(dp[j], dp[i] + 1)
	ans = 0
	for i in graph:
		ans = max(len(graph[i]) * dp[i], ans)
	print(ans)
except Exception as e:
	print(e)


(n, m) = map(int, input().split())
L = [[] for i in range(n + 1)]
for i in range(m):
	edge = list(map(int, input().split()))
	L[edge[0]].append(edge[1])
	L[edge[1]].append(edge[0])
ans = 0
d = [1] * (n + 1)
for i in range(1, n + 1):
	ans = max(ans, d[i] * len(L[i]))
	for j in L[i]:
		if j > i:
			d[j] = max(d[j], d[i] + 1)
print(ans)


(n, m) = map(int, input().split())
G = [list() for i in range(n + 1)]
colored = [False] * (n + 1)
hhog_tail = [1] * (n + 1)
spine_count = [0] * (n + 1)

def find_best_hhog_tail(z):
	if colored[z]:
		return
	colored[z] = True
	for y in G[z]:
		if not colored[y]:
			find_best_hhog_tail(y)
		hhog_tail[z] = max(hhog_tail[z], 1 + hhog_tail[y])
for i in range(m):
	(u, v) = map(int, input().split())
	G[u].append(v) if u > v else G[v].append(u)
	spine_count[u] += 1
	spine_count[v] += 1
for i in range(1, n + 1):
	find_best_hhog_tail(i)
print(max([spine_count[i] * hhog_tail[i] for i in range(1, n + 1)]))


(n, m) = map(int, input().split())
neibs_count = [0 for _ in range(n + 1)]
max_len = [0 for _ in range(n + 1)]
prevs = [[] for _ in range(n + 1)]
for _ in range(m):
	(a, b) = map(int, input().split())
	prevs[max(a, b)].append(min(a, b))
	neibs_count[a] += 1
	neibs_count[b] += 1
max_ans = 0
for i in range(1, n + 1):
	max_prev_len = 0
	for prev in prevs[i]:
		max_prev_len = max(max_prev_len, max_len[prev])
	max_len[i] = max_prev_len + 1
	max_ans = max(max_ans, max_len[i] * neibs_count[i])
print(max_ans)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5 + 10)

def dfs(v):
	if memo[v] != -1:
		return memo[v]
	res = 1
	for nv in G[v]:
		res = max(res, dfs(nv) + 1)
	memo[v] = res
	return res
(n, m) = map(int, input().split())
d = [0] * n
G = [[] for _ in range(n)]
for _ in range(m):
	(u, v) = map(int, input().split())
	d[u - 1] += 1
	d[v - 1] += 1
	G[max(u, v) - 1].append(min(u, v) - 1)
memo = [-1] * n
ans = 0
for i in range(n):
	ans = max(ans, d[i] * dfs(i))
print(ans)


(n, m) = map(int, input().split())
child = [[] for _ in range(n + 1)]
deg = [0 for _ in range(n + 1)]
for i in range(m):
	(u, v) = map(int, input().split())
	if u > v:
		(u, v) = (v, u)
	child[u].append(v)
	deg[u] += 1
	deg[v] += 1
depth = [0 for _ in range(n + 1)]
res = deg[1]
for u in range(1, n + 1):
	for v in child[u]:
		depth[v] = max(depth[v], depth[u] + 1)
		res = max(res, (depth[v] + 1) * deg[v])
print(res)


(n, m) = tuple(map(int, input().split()))
g = [set() for i in range(n + 1)]
for i in range(m):
	a = tuple(map(int, input().split()))
	g[a[1]].add(a[0])
	g[a[0]].add(a[1])
res = [0] * (n + 1)
for i in range(1, n + 1):
	maxi = 1
	for elem in g[i]:
		if elem > i:
			continue
		if res[elem] + 1 > maxi:
			maxi = res[elem] + 1
	res[i] = maxi
m = [0] * (n + 1)
for i in range(1, n + 1):
	m[i] = res[i] * len(g[i])
print(max(m))


def read():
	return list(map(int, input().split()))
(n, m) = read()
lst = [[] for _ in range(n + 1)]
for _ in range(m):
	(u, v) = read()
	lst[u].append(v)
	lst[v].append(u)
d = [1] * (n + 1)
ans = 0
for v in range(1, n + 1):
	ans = max(ans, d[v] * len(lst[v]))
	for u in lst[v]:
		if u > v:
			d[u] = max(d[u], d[v] + 1)
print(ans)


(n, m) = map(int, input().split())
gr = {o: set() for o in range(n)}
for _ in range(m):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	gr[a].add(b)
	gr[b].add(a)
d = [1] * n
for v in range(n):
	for u in gr[v]:
		if u < v:
			d[v] = max(d[v], 1 + d[u])
ans = 0
for v in range(n):
	ans = max(ans, len(gr[v]) * d[v])
print(ans)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [Scanner.string() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [Scanner.int() for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def solve():
	(N, M) = Scanner.map_int()
	G = [list() for _ in range(N)]
	for _ in range(M):
		(x, y) = Scanner.map_int()
		x -= 1
		y -= 1
		G[x].append(y)
		G[y].append(x)
	dp = [1 for _ in range(N)]
	for i in range(N):
		p = dp[i]
		for g in G[i]:
			if g > i:
				dp[g] = max(p + 1, dp[g])
	ans = 0
	for i in range(N):
		ans = max(ans, len(G[i]) * dp[i])
	print(ans)

def main():
	solve()
main()


from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(10 ** 5)
from collections import defaultdict
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
PI = float('inf')

def dfs(src):
	vis[src] = 1
	for neigh in g[src]:
		if neigh < src:
			if not vis[neigh]:
				dfs(neigh)
			dp[src] = max(dp[src], 1 + dp[neigh])
for _ in range(1):
	(n, eg) = lst()
	g = defaultdict(list)
	for i in range(eg):
		(u, v) = lst()
		g[u] += [v]
		g[v] += [u]
	dp = [1] * (1 + n)
	vis = [0] * (1 + n)
	for node in range(1, n + 1):
		if not vis[node]:
			dfs(node)
	print(max((len(g[node]) * dp[node] for node in range(1, n + 1))))


(n, m) = list(map(int, input().split()))
d = [0] * n
f = [[] for i in range(n)]
for i in range(m):
	a = list(map(int, input().split()))
	d[a[0] - 1] += 1
	d[a[1] - 1] += 1
	a.sort()
	f[a[1] - 1] += [a[0] - 1]
k = [1] * n
res = 0
for i in range(n):
	for j in f[i]:
		k[i] = max(k[i], k[j] + 1)
	res = max(res, k[i] * d[i])
print(res)


import sys

def dfs(v):
	nonlocal g, links, used, tail, val
	used[v] = True
	maxv = 1
	for u in g[v]:
		if not used[u]:
			dfs(u)
		maxv = max(maxv, tail[u] + 1)
	val[v] = links[v] * maxv
	tail[v] = maxv
fin = sys.stdin
(n, m) = map(int, fin.readline().split())
g = [[] for i in range(n)]
links = [0] * n
for i in range(m):
	(u, v) = map(int, fin.readline().split())
	(u, v) = (u - 1, v - 1) if u <= v else (v - 1, u - 1)
	g[v].append(u)
	links[v] += 1
	links[u] += 1
used = [False] * n
(val, tail) = ([0] * n, [0] * n)
maxv = 0
for i in range(n):
	if not used[i]:
		dfs(i)
	maxv = max(maxv, val[i])
print(maxv)


(n, m) = list(map(int, input().split()))
gro = [[] * n for i in range(n)]
grno = [[] * n for i in range(n)]
ln = [1] * n
for i in range(m):
	(x, y) = list(map(int, input().split()))
	if x < y:
		gro[x - 1].append(y - 1)
	else:
		gro[y - 1].append(x - 1)
	grno[x - 1].append(y - 1)
	grno[y - 1].append(x - 1)
for i in range(n):
	for j in gro[i]:
		if ln[j] <= ln[i] + 1:
			ln[j] = ln[i] + 1
mx = 0
for i in range(n):
	if ln[i] * len(grno[i]) > mx:
		mx = ln[i] * len(grno[i])
print(mx)


(n, m) = [int(i) for i in input().split()]
seg = {i: [] for i in range(1, n + 1)}
for j in range(m):
	(a, b) = [int(i) for i in input().split()]
	seg[a].append(b)
	seg[b].append(a)
tail = [0] * (n + 1)
tail[1] = 1
for i in range(2, n + 1):
	temp = [tail[j] for j in seg[i]] + [0]
	tail[i] = max(temp) + 1
temp = [len(seg[i]) * tail[i] for i in range(1, n + 1)]
print(max(temp))


inp = input().split()
(n, m) = (int(inp[0]), int(inp[1]))
a = [[] for _ in range(n + 1)]
for i in range(m):
	inp = input().split()
	(x, y) = (int(inp[0]), int(inp[1]))
	a[x - 1].append(y - 1)
	a[y - 1].append(x - 1)
dp = [1 for _ in range(n)]
for i in range(n):
	for j in range(len(a[i])):
		if i < a[i][j]:
			dp[a[i][j]] = max(dp[a[i][j]], dp[i] + 1)
ans = 0
for i in range(n):
	ans = max(ans, dp[i] * len(a[i]))
print(ans)


class graph:

	def __init__(self, n):
		self.n = n
		self.adj = [[] for _ in range(n)]

	def adde(self, n, m):
		self.adj[n].append(m)
		self.adj[m].append(n)

	def findmax(self):
		mscore = 0
		for node in range(self.n):
			tail = self.DFS(node)
			spines = len(self.adj[node])
			mscore = max(tail * spines, mscore)
			print(tail, spines, mscore)
		return mscore

	def DFS(self, s):
		ml = 0
		for edge in self.adj[s]:
			if edge > s:
				continue
			ml = max(self.DFS(edge), ml)
		return ml + 1

	def dp(self):
		pathlengths = [1 for _ in self.adj]
		maxscore = 0
		for i in range(self.n):
			local_max = 1
			for node in self.adj[i]:
				if node < i:
					local_max = max(local_max, pathlengths[node] + 1)
			pathlengths[i] = local_max
			maxscore = max(maxscore, local_max * len(self.adj[i]))
		return maxscore
(n, m) = [int(x) for x in input().split()]
g = graph(n)
for _ in range(m):
	(u, v) = [int(x) for x in input().split()]
	g.adde(u - 1, v - 1)
print(g.dp())


max_n = 100005
V = [[] for i in range(max_n)]
deg = [0] * max_n
dist = [0] * max_n
data = input().split(' ')
n = int(data[0])
m = int(data[1])
for i in range(m):
	data = input().split(' ')
	u = int(data[0])
	v = int(data[1])
	V[u].append(v)
	V[v].append(u)
	deg[u] += 1
	deg[v] += 1
res = -1
for i in range(1, n + 1):
	for j in range(len(V[i])):
		t = V[i][j]
		if i > t:
			dist[i] = max(dist[i], dist[t] + 1)
		res = max(res, (dist[i] + 1) * deg[i])
print(res)


class Node:

	def __init__(self, i):
		self.i = i
		self.adj = []

def draw_hedgehog(n, nodes):
	tail_length = [1] * n
	best_beauty = len(nodes[0].adj)
	for i in range(1, n):
		max_so_far = tail_length[i]
		best_length = tail_length[i]
		spines = len(nodes[i].adj)
		for j in nodes[i].adj:
			if j < i:
				beauty = (tail_length[j] + 1) * spines
				if beauty > max_so_far:
					max_so_far = beauty
					best_length = tail_length[j] + 1
		tail_length[i] = best_length
		if max_so_far > best_beauty:
			best_beauty = max_so_far
	return best_beauty
(n, m) = input().split()
(n, m) = (int(n), int(m))
nodes = [Node(i) for i in range(n)]
for k in range(m):
	(u, v) = input().split()
	(u, v) = (int(u) - 1, int(v) - 1)
	nodes[u].adj.append(v)
	nodes[v].adj.append(u)
result = draw_hedgehog(n, nodes)
print(result)


from collections import defaultdict
graph = defaultdict(list)
(n, m) = list(map(int, input().split()))
for i in range(m):
	(v, u) = list(map(int, input().split()))
	graph[v].append(u)
	graph[u].append(v)
dp = [1] * (n + 1)
ans = len(graph[1])
for i in range(2, n + 1):
	for v in graph[i]:
		if v < i:
			dp[i] = max(dp[i], dp[v] + 1)
	ans = max(ans, dp[i] * len(graph[i]))
print(ans)


def max_hedgehog(g):
	t = []
	mh = 0
	for (i, ni) in enumerate(g):
		k = len(ni)
		mt = max((t[j] + 1 for j in ni if j < i), default=1)
		t.append(mt)
		h = k * mt
		mh = max(h, mh)
	return mh
(n, m) = map(int, input().split())
g = tuple((set() for _ in range(n)))
for _ in range(m):
	(u, v) = map(int, input().split())
	g[u - 1].add(v - 1)
	g[v - 1].add(u - 1)
print(max_hedgehog(g))


(n, m) = map(int, input().split())
a = []
for _ in range(n):
	a.append([])
max_b = [0] * n
maximum = 0
for i in range(m):
	(x, y) = map(int, input().split())
	a[x - 1].append(y - 1)
	a[y - 1].append(x - 1)
for i in range(n):
	max_b[i] = 1
	for v in a[i]:
		if v < i:
			max_b[i] = max(max_b[i], max_b[v] + 1)
	maximum = max(maximum, max_b[i] * len(a[i]))
print(maximum)


(n, m) = map(int, input().split())
graph = [[i] for i in range(n + 2)]
dn = [0 for _ in range(n + 2)]
res = 0
for _ in range(m):
	(a, b) = map(int, input().split())
	graph[a].append(b)
	graph[b].append(a)
for node in range(1, n + 1):
	dn[node] = dn[max(graph[node] if graph[node] else [n + 1], key=lambda adj: dn[adj] + 1 if adj < node else 0)] + 1
	res = max(res, dn[node] * (len(graph[node]) - 1))
print(res)


(n, m) = map(int, input().split())
ans = 0
dp = [1] * n
deg = [0] * n
G = [[] for i in range(n)]
for i in range(m):
	(x, y) = map(int, input().split())
	if x > y:
		(x, y) = (y, x)
	x -= 1
	y -= 1
	deg[x] += 1
	deg[y] += 1
	G[x].append(y)
for i in range(n):
	ans = max(ans, dp[i] * deg[i])
	for j in G[i]:
		dp[j] = max(dp[j], dp[i] + 1)
print(ans)


import sys
(n, m) = sys.stdin.readline().split()
n = int(n)
m = int(m)
neighbours = []
ne = []
smaller = []
for i in range(n):
	neighbours.append(0)
	smaller.append(1)
	ne.append([])
for i in range(m):
	(f, t) = sys.stdin.readline().split()
	f = int(f) - 1
	t = int(t) - 1
	neighbours[f] += 1
	neighbours[t] += 1
	if f < t:
		ne[f].append(t)
	else:
		ne[t].append(f)
for i in range(n):
	for sysed in ne[i]:
		smaller[sysed] = max([smaller[sysed], smaller[i] + 1])
ans = 0
for i in range(n):
	ans = max([ans, smaller[i] * neighbours[i]])
print(ans)