#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    vector<int> vis(n, -1);
    vector<bool> dfn(n, false);
    vector<int> sz(n, 0);
    vector<vector<int>> adj(n, vector<int>(n));
    long long res = 0;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
        adj[u][v] = adj[v][u] = 1;
    }
    vector<int> p;
    function<void(int)> dfs1 = [&](int now) {
        dfn[now] = true;
        for (auto to : g[now]) {
            if (!dfn[to]) {
                p.push_back(to);
                dfs1(to);
            }
        }
    };
    function<long long(int)> dfs2 = [&](int dep) -> long long {
        if (dep == p.size()) {
            return 1;
        }
        vector<bool> can(3, true);
        for (auto to : g[p[dep]]) {
            if (vis[to] != -1) {
                can[vis[to]] = false;
            }
        }
        if (!can[0] && !can[1] && !can[2]) return 0;
        long long ret = 0;
        if (!dep) {
            vis[p[dep]] = 0;
            ret += 3LL * dfs2(dep + 1);
            vis[p[dep]] = -1;
        } else {
            for (int c = 0; c < 3; c++) {
                if (can[c]) {
                    vis[p[dep]] = c;
                    ret += dfs2(dep + 1);
                    vis[p[dep]] = -1;
                }
            }
        }
        return ret;
    };
    for (int i = 0; i < n; i++) {
        if (!dfn[i]) {
            p.clear();
            p.push_back(i);
            dfs1(i);
            auto tmp = dfs2(0);
            if (tmp) {
                if (res) res *= tmp;
                else res += tmp;
            }
        }
    }
    cout << res;
    return 0;
}
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast")
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<ll> VL;
typedef vector<vector<ll>> VLL;
constexpr int mod = 1e9 + 7;
constexpr int KINF = 0x3f3f3f3f;
constexpr int INF = 0x7f7f7f7f;
constexpr double eps = 1e-7;
int main(){
	ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr);
	int n, m;
	cin >> n >> m;
	VII g(n);
	_rep(i, 0, m){
		int u, v;
		cin >> u >> v;
		g[--u].eb(--v);
		g[v].eb(u);
	}
	vector<int> be;//在同一个连通块的点
	VI vis(n), col(n);
	auto find = [&](auto&& self, int x) -> void{
		be.eb(x);
		vis[x] = 1;
		for(int& v : g[x])
			if(!vis[v]) self(self, v);
	};
	int res = 0;
	auto dfs = [&](auto&& self, int id) -> void{
		if(id == (int)be.size()){
			res++;
			return;
		}
		int u = be[id];
		_rep(i, 1, 4){
			bool ok = true;
			for(int& v : g[u]) if(col[v] == i) ok = false;
			if(!ok) continue;// 当前节点不能染成颜色i
			col[u] = i;
			self(self, id + 1);
			col[u] = 0;
		}
	};
	ll ans = 1;
	_rep(i, 0, n){
		if(!vis[i]){
			be.clear();
			find(find, i);// 求出连通块
			dfs(dfs, 0);
			ans *= res;
			res = 0;
		}
	}
	cout << ans << endl;
	return 0;
} 
// 小心左移运算符导致的int溢出
// dp记得处理非法状态
// resize并不会初始化数组
// 全局函数一定要记得inline
// 带空格字符串不能直接cin,要用getline
// 最好用用"\n"代替endl

