Problem:
Score : 700 points

Problem Statement

You are given a simple connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge connects Vertex A_i and Vertex B_i.
Takahashi will assign one of the two possible directions to each of the edges in the graph to make a directed graph.
Determine if it is possible to make a directed graph with an even number of edges going out from every vertex. If the answer is yes, construct one such graph.

Notes

An undirected graph is said to be simple when it contains no self-loops or multiple edges.

Constraints

2 \leq N \leq 10^5

N-1 \leq M \leq 10^5

1 \leq A_i,B_i \leq N (1\leq i\leq M)

The given graph is simple and connected.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
:
A_M B_M

Output

If it is impossible to assign directions to satisfy the requirement, print -1.
Otherwise, print an assignment of directions that satisfies the requirement, in the following format:

C_1 D_1
:
C_M D_M

Here each pair (C_i, D_i) means that there is an edge directed from Vertex C_i to Vertex D_i. The edges may be printed in any order.

Sample Input 1

4 4
1 2
2 3
3 4
4 1

Sample Output 1

1 2
1 4
3 2
3 4

After this assignment of directions, Vertex 1 and 3 will each have two outgoing edges, and Vertex 2 and 4 will each have zero outgoing edges.

Sample Input 2

5 5
1 2
2 3
3 4
2 5
4 5

Sample Output 2

-1

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
//using System.Threading.Tasks;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    readonly int dom = 998244353;
    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void solve()
    {
        int N = cin.nextint;
        int M = cin.nextint;
        if (M % 2 == 1)
        {
            WriteLine(-1);
            return;
        }
        var G = new HashSet<int>[N];
        for (int i = 0; i < G.Length; i++)
        {
            G[i] = new HashSet<int>();
        }

        for (int i = 0; i < M; i++)
        {
            int a = cin.nextint - 1;
            int b = cin.nextint - 1;
            G[a].Add(b);
            G[b].Add(a);
        }

        var Q = new Queue<int>();
        int any = -1;
        var used = new bool[N];
        var cnt = new int[N];

        for (int i = 0; i < N; i++)
        {
            if (G[i].Count % 2 == 1)
            {
                Q.Enqueue(i);
                used[i] = true;
            }
            if (G[i].Count > 0)
            {
                any = i;
            }
        }
        if (Q.Count == 0)
        {
            Q.Enqueue(any);
            used[any] = true;
        }

        var SB = new SB();
        while (Q.Count > 0)
        {
            var d = Q.Dequeue();
            //全部使う
            if ((cnt[d] + G[d].Count) % 2 == 0)
            {
                //Write("0:");
                foreach (var v in G[d])
                {
                    cnt[d]++;
                    G[v].Remove(d);
                   SB.AppendLine($"{d + 1} {v + 1}");
                    if (!used[v] && G[v].Count % 2 == 1)
                    {
                        used[v] = true;
                        Q.Enqueue(v);
                    }
                }
            }
            else if (cnt[d] % 2 == 0)//全部使わない
            {
                //Write("1:");

                foreach (var v in G[d])
                {
                    cnt[v]++;
                    G[v].Remove(d);
                    SB.AppendLine($"{v + 1} {d + 1}");
                    if (!used[v] && G[v].Count % 2 == 1)
                    {
                        used[v] = true;
                        Q.Enqueue(v);
                    }
                }
                
            }
            else if(G[d].Count > 0)//1つ使う
            {
                //Write("2:");

                int first = G[d].First();
                cnt[d]++;
                G[first].Remove(d);
                SB.AppendLine($"{d + 1} {first + 1}");
                G[d].Remove(first);
                foreach (var v in G[d])
                {
                    cnt[v]++;
                    G[v].Remove(d);
                    WriteLine($"{v + 1} {d + 1}");
                    if (!used[v] && G[v].Count % 2 == 1)
                    {
                        used[v] = true;
                        Q.Enqueue(v);
                    }
                }
            }
            else
            {
                WriteLine(-1);
                return;
            }
            G[d].Clear();


        }
        Write(SB);

        //bool flag = true;
        //while (flag)
        //{
        //    flag = false;
        //    int any = -1;
        //    var Q = new Queue<int>();
        //    for (int i = 0; i < N; i++)
        //    {
        //        if (G[i].Count % 2 == 1)
        //        {
        //            Q.Enqueue(i);
        //        }
        //        if (G[i].Count > 0)
        //        {
        //            any = i;
        //        }
        //    }
        //    if (Q.Count == 0 && any != -1)
        //    {
        //        Q.Enqueue(any);
        //    }
        //    if (Q.Any())
        //    {
        //        flag = true;
        //    }

        //    while (Q.Any())
        //    {

        //    }
        //}

    }

}


static class Ex
{
    public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values));
    public static string concat<T>(this IEnumerable<T> values) => string.Concat(values);
    public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }

    public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) <= 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f; public U s;
    public Pair(T f, U s) { this.f = f; this.s = s; }
    public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    public override string ToString() => $"{f} {s}";
}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan => ReadLine().Split();
    public int[] scanint => Array.ConvertAll(scan, int.Parse);
    public long[] scanlong => Array.ConvertAll(scan, long.Parse);
    public double[] scandouble => Array.ConvertAll(scan, double.Parse);
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint => int.Parse(next);
    public long nextlong => long.Parse(next);
    public double nextdouble => double.Parse(next);
}