#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

//#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
//typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

inline int nextInt()
{
    int x = 0;
    char c = getchar();
    int mi = (c == '-');
    if (c == '-') c = getchar();
    while ('0' <= c && c <= '9')
    {
        x = 10 * x + c - '0';
        c = getchar();
    }
    if (mi) return x * -1;
    return x;
}

int n, m;
vector<int> graph[550000];
int color[550000];
int BITPARTITE = 1;
vector<int> bp, p;
int SZ = 0;

int dfs(int v, int fl)
{
    color[v] = fl;
    SZ++;
    for (auto u : graph[v])
    {
        if (color[u] == 0) dfs(u, 3 - fl);
        if (color[u] == fl) BITPARTITE = 0;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int v, u;
        cin >> v >> u;
        v--, u--;
        graph[v].push_back(u);
        graph[u].push_back(v);
    }
    ll ans = 0;
    ll cnt = n - 1;
    for (int i = 0; i < n; i++)
    {
        if (graph[i].size() == 0)
        {
            ans += 2 * cnt + 1;
            cnt--;
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (color[i] == 0 && graph[i].size() != 0)
        {
            BITPARTITE = 1;
            SZ = 0;
            dfs(i, 1);
            if (BITPARTITE) bp.push_back(SZ);
            else p.push_back(SZ);
        }
    }
    cout << ans + 2LL * bp.size() * bp.size() + p.size() * p.size() + 2LL * bp.size() * p.size();
}

#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, M;
    cin >> N >> M;
    VEC(VEC(int)) Edges(N);
    FOR(i, 0, M) {
        int u, v;
        cin >> u >> v;
        Edges[u - 1].push_back(v - 1);
    }

    VEC(VEC(int)) Reach(N, VEC(int)(N, 10000));
    FOR(i, 0, N) {
        VEC(int)& Bfs = Reach[i];
        queue<int> q;
        q.push(i);

        while (q.size()) {
            int v = q.front();
            q.pop();
            for (int u : Edges[v])
                if (Bfs[u] >= 10000) {
                    q.push(u);
                    int dist = v == i ? 0 : Bfs[v];
                    Bfs[u] = 1 + dist;
                }
        }
    }

    VEC(int) cycle(10000, 0);
    FOR(i, 0, N)
        if (cycle.size() >= 10000 || Reach[i][i] < cycle.size()) {
            cycle.clear();
            int node = i, dist = Reach[i][i];
            while (dist--) {
                cycle.push_back(node);
                for (int next : Edges[node]) {
                    if (next == i) {
                        goto done;
                    }

                    if (Reach[next][i] == dist) {
                        node = next;
                        break;
                    }
                }
            }

done:
            continue;
        }

    if (cycle.size() >= 10000) {
        cout << -1 << endl;
        return 0;
    }

    cout << cycle.size() << endl;
    for (int v : cycle)
        cout << (v + 1) << endl;
    return 0;
};