Buggy python submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]
N, M = map(int, input().split())
es = [[] for i in range(N+1)]
edge = [None] * M
h = [0] * (N+1)
for id in range(M):
    a, b = map(int, input().split())
    es[a].append([b, id])
    edge[id] = [a, b]
    h[a] += 1

def rev(v, p, t, visit):
    if v == t:
        return True
    visit[v] = 0
    for i, (u, id) in enumerate(es[v]):
        if u != -1 and visit[u] and rev(u, v, t, visit):
            es[v][i] = [-1, id]
            es[u].append([v, id])
            edge[id] = [u, v]
            h[v] -= 1
            h[u] += 1

ps, pt, s, t = 0, 0, 0, 0
for i in range(N):
    for v in range(t+1, N+1):
        if h[v] % 2:
            s = v
            break
    if s == ps:
        break
    for v in range(s+1, N+1):
        if h[v] % 2:
            t = v
            break
    if t == pt:
        print(-1)
        quit()
    rev(s, -1, t, [1] * (N+1))
    ps, pt = s, t
for u, v in edge:
    print(u, v)


Fixed submission:
from heapq import *
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()[:-1]
N, M = map(int, input().split())
es = [[] for i in range(N+1)]
for id in range(M):
    a, b = map(int, input().split())
    es[a].append([b, id])
    es[b].append([a, id])
edge = [None] * M
h = [0] * (N+1)
lev = [None] * (N+1)
visit = [0] * (N+1)
def dfs(v, d):
    if visit[v]: return
    lev[v] = d
    visit[v] = 1
    for u, id in es[v]:
        if edge[id] == None:
            edge[id] = [v, u]
            h[v] ^= 1
            dfs(u, d+1)
dfs(1, 0)
q = [(-lev[v], v) for v in range(1, N+1)]
heapify(q)
while q:
    lv, v = heappop(q)
    lv = -lv
    if h[v] % 2 == 0: continue
    for u, id in es[v]:
        if lev[u] < lv:
            h[v] ^= 1
            h[u] ^= 1
            k, l = edge[id]
            edge[id] = [l, k]
            break
if h[1]:
    print(-1)
else:
    for u, v in edge:
        print(u, v)

Buggy python submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]
N, M = map(int, input().split())
es = [[] for i in range(N+1)]
edge = [None] * M
h = [0] * (N+1)
for id in range(M):
    a, b = map(int, input().split())
    es[a].append([b, id])
    edge[id] = [a, b]
    h[a] += 1

def rev(v, p, t, visit):
    if v == t:
        return True
    visit[v] = 0
    for i, (u, id) in enumerate(es[v]):
        if u != -1 and visit[u] and rev(u, v, t, visit):
            es[v][i] = [-1, id]
            es[u].append([v, id])
            edge[id] = [u, v]
            h[v] -= 1
            h[u] += 1

ps, pt, s, t = 0, 1, 0, 0
while True:
    for v in range(t+1, N+1):
        if h[v] % 2:
            s = v
            break
    if s == ps:
        break
    for v in range(s+1, N+1):
        if h[v] % 2:
            t = v
            break
    if t == pt:
        print(-1)
        quit()
    rev(s, -1, t, [1] * (N+1))
    ps, pt = s, t
for u, v in edge:
    print(u, v)


Fixed submission:
from heapq import *
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()[:-1]
N, M = map(int, input().split())
es = [[] for i in range(N+1)]
for id in range(M):
    a, b = map(int, input().split())
    es[a].append([b, id])
    es[b].append([a, id])
edge = [None] * M
h = [0] * (N+1)
lev = [None] * (N+1)
visit = [0] * (N+1)
def dfs(v, d):
    if visit[v]: return
    lev[v] = d
    visit[v] = 1
    for u, id in es[v]:
        if edge[id] == None:
            edge[id] = [v, u]
            h[v] ^= 1
            dfs(u, d+1)
dfs(1, 0)
q = [(-lev[v], v) for v in range(1, N+1)]
heapify(q)
while q:
    lv, v = heappop(q)
    lv = -lv
    if h[v] % 2 == 0: continue
    for u, id in es[v]:
        if lev[u] < lv:
            h[v] ^= 1
            h[u] ^= 1
            k, l = edge[id]
            edge[id] = [l, k]
            break
if h[1]:
    print(-1)
else:
    for u, v in edge:
        print(u, v)