#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
const int N = 2e5 + 7;
const int M = 1e6 + 7;
const int INF = 1e9 + 8;
vector<int> G[N];
int vis[N];
int ans = 0;
void dfs(int x, int fa, int &flag) {
  vis[x] = 1;
  if (G[x].size() != 2) flag = 1;
  for (int i = 0; i < G[x].size(); i++) {
    if (!vis[G[x][i]]) dfs(G[x][i], fa, flag);
  }
}
int main() {
  int n, m;
  int u, v;
  cin >> n >> m;
  memset(vis, 1, sizeof vis);
  for (int i = 1; i <= m; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
    vis[u] = vis[v] = 0;
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      int flag = 0;
      dfs(i, i, flag);
      if (!flag) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
