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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m; cin >> n >> m;
    vector<vector<int>> adj(n);
    for (int i = 0; i < m; ++i) {
        int u, v; cin >> u >> v; --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector<bool> vis(n, 0);
    int sz;
    function<void(int)> dfs1 = [&](int u) {
        sz++;
        vis[u] = 1;
        for (int v : adj[u]) 
            if (!vis[v]) dfs1(v);
    };
    
    int offset, pos;
    vector<int> colour(n);
    function<bool(int)> dfs2 = [&](int u) {
        pos++;
        for (int v : adj[u]) {
            if (colour[v] == colour[u]) {
                return false;
            }
            if (colour[v] == -1) {
                colour[v] = (colour[u] + ((offset >> pos) & 1) + 1) % 3;
                if (!dfs2(v)) return false;
            }
        }
        return true;
    };

    long long ans = 1;
    for (int i = 0; i < n; ++i) {
        if (vis[i]) continue;
        sz = 0;
        dfs1(i);
        int cur = 0;
        for (offset = 0; offset < (1 << (sz - 1)); ++offset) {
            colour.assign(n, -1);
            colour[i] = 0;
            pos = -1;
            if (dfs2(i)) cur += 3;
        }
        ans *= cur;
    }
    cout << ans << '\n';

    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
using P = pair<int,int>;

int main(){
  int n, m;
  cin >> n >> m;
  vector<P> v(n);
  vector<vector<int>> g(n);
  vector<int> a(m), b(m);
  rep(i,m) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  vector<int> c(n,-1);
  ll cnt = 0;
  rep(i,n) if(g[i].size() == 0) cnt++;
  ll ans = 0;
  auto dfs = [&](auto self, int id) -> void {
    if(id == m) {
      ans++;
      return;
    }
    if(c[a[id]] != -1 and c[b[id]] != -1) {
      if(c[a[id]] != c[b[id]]) self(self,id+1);
    } else if(c[a[id]] != -1) {
      rep(i,3) if(i != c[a[id]]) {
        c[b[id]] = i;
        self(self,id+1);
        c[b[id]] = -1;
      }
    } else if(c[b[id]] != -1) {
      rep(i,3) if(i != c[b[id]]) {
        c[a[id]] = i;
        self(self,id+1);
        c[a[id]] = -1;
      }
    } else {
      rep(i,3) rep(j,3) {
        if(i != j) {
          c[a[id]] = i, c[b[id]] = j;
          self(self,id+1);
          c[a[id]] = -1, c[b[id]] = -1;
        }
      }
    }
    return;
  };
  dfs(dfs,0);
  rep(i,cnt) ans *= 3;
  cout << ans << endl;
  return 0;
}
