#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int vis[MAXN], ok;
vector<int> G[MAXN];
void dfs(int v) {
  vis[v] = 1;
  if (G[v].size() != 2) ok = 0;
  for (int u : G[v]) {
    if (vis[u]) continue;
    dfs(u);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      ok = 1;
      dfs(i);
      res += ok;
    }
  }
  cout << res << "\n";
}
