#include <bits/stdc++.h>

using i64 = long long;

void chmin(int &a, int b)
{
    if (a > b)
    {
        a = b;
    }
}

void chswap(int &a, int &b)
{
    int tmp = a;
    a = b;
    b = tmp;
}

const int lim = 1e3 + 5;

int n, m, timer, scc;

std::vector<int> low(lim), d(lim), sz(lim), ssc(lim), in(lim), out(lim), visited(lim);
std::vector<std::vector<int>> adj(lim), node(lim);
std::vector<std::vector<std::array<int, 2>>> adj1(lim);
std::stack<int> st;
bool done[lim];

void tarjan(int u)
{
    low[u] = d[u] = ++timer;

    st.push(u);

    for (int v : adj[u])
    {
        if (done[v] == false)
        {
            if (d[v])
            {
                chmin(low[u], d[v]);
            }
            else
            {
                tarjan(v);

                chmin(low[u], low[v]);
            }
        }
    }

    if (low[u] == d[u])
    {
        int v;
        ++scc;
        do
        {
            v = st.top();
            st.pop();

            done[v] = true;

            ssc[v] = scc;
            ++sz[scc];

            node[ssc[v]].push_back(v);
        } while (v != u);
    }
}

int remove_id;

/*
visited:
1 - is visiting
2 - visited
3 - is not visit
*/

bool isCycle(int u)
{
    visited[u] = 1;

    for (std::array<int, 2> &cur : adj1[u]) if (cur[1] != remove_id)
    {
        int v = cur[0];

        if (visited[v] == 1) return true;

        if (visited[v] == 0)
        {
            if (isCycle(v))
            {
                return true;
            }
        }
    }

    visited[u] = 2;

    return false;
}

bool will_this_DAG_is_cycle_if_we_remove_edge(int u, int v, int id)
{
    remove_id = id;
    if (ssc[u] == ssc[v])
    {
        for (int i : node[ssc[u]]) visited[i] = 0;

        for (int i : node[ssc[u]])
        {
            if (visited[i] == 0)
            {
                if (isCycle(i)) return false;
            }
        }
    }

    return true;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin >> n >> m;

    std::vector<std::array<int, 2>> edges(m), conditional_edges, ans;

    for (int i = 0; i < m; ++i)
    {
        int u, v;
        std::cin >> u >> v;

        adj[u].push_back(v);

        edges[i] = {u, v};
    }

    for (int i = 1; i <= n; ++i)
        if (!d[i])
            tarjan(i);

    std::cerr << scc << "\n";

    bool has_cycle = false;
    int cycle = 0;
    int strong_components_have_one_cycle = 0;

    for (int i = 1; i <= scc; ++i)
    {
        has_cycle = false;

        if (sz[i] > 1) has_cycle = true;
        else
        {
            for (int _i = 0; _i < m; ++_i)
            {
                int u = edges[_i][0];
                int v = edges[_i][1];
                if (u == v and ssc[u] == i and ssc[v] == i)
                {
                    has_cycle = true;
                    break;
                }
            }
        }

        if (has_cycle)
        {
            ++cycle;
            strong_components_have_one_cycle = i;
        }
    }

    if (cycle != 1)
    {
        std::cout << -1 << "\n";
        return 0;
    }

    for (int i = 0; i < m; ++i)
    {
        int u = edges[i][0];
        int v = edges[i][1];

        if (ssc[u] == strong_components_have_one_cycle and ssc[v] == strong_components_have_one_cycle)
        {
            ++out[u], ++in[v];

            adj1[u].push_back({v, i});
            conditional_edges.push_back({u, v});
        }
    }

    // std::cout << strong_components_have_one_cycle << "\n";

    // std::cout << (int)conditional_edges.size() << "\n";

    bool is_simpleCycle = true;

    for (int i = 1; i <= n; ++i)
    {
        if (ssc[i] == strong_components_have_one_cycle)
        {
            if (in[i] != 1 || out[i] != 1)
            {
                is_simpleCycle = false;
            }
        }
    }

    if (is_simpleCycle)
    {
        std::cerr << "is simple cycle\n";
        ans = conditional_edges;
    }
    else
    {
        std::cerr << "is not simple cycle\n";
        for (int i = 0; i < m; ++i)
        {
            int u = edges[i][0];
            int v = edges[i][1];

            if (ssc[u] == strong_components_have_one_cycle and ssc[v] == strong_components_have_one_cycle)
            {
                if (will_this_DAG_is_cycle_if_we_remove_edge(u, v, i))
                {
                    ans.push_back({u, v});
                }
            }
        }
    }

    std::sort(ans.begin(), ans.end());
    ans.erase(std::unique(ans.begin(), ans.end()), ans.end());

    std::cout << (int)ans.size() << "\n";

    for (std::array<int, 2> &edge : ans)
    {
        int u = edge[0];
        int v = edge[1];

        std::cout << u << ' ' << v << "\n";
    }

    return 0;

}
