#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
bool vis[200003];
bool vis2[200003];
vector<int> adj[200003];
int god;
int l;
void dfs(int x, int par) {
  vis[x] = true;
  ++l;
  for (auto d : adj[x]) {
    if (d == par) continue;
    if (!vis[d]) dfs(d, x);
  }
}
bool dfs2(int x, int par, int p) {
  vis2[x] = true;
  ++p;
  if (p == l) {
    if (l <= 2) return false;
    for (auto d : adj[x])
      if (d == god) return true;
    return false;
  }
  bool b = false;
  if (adj[x].size() > 2) return false;
  for (auto d : adj[x]) {
    if (d == par) continue;
    if (!vis2[d]) return dfs2(d, x, p);
  }
  vis2[x] = false;
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  int a, b;
  for (long long i = 0; i < m; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int ct = 0;
  for (long long i = 1; i < n + 1; i++) {
    if (!vis[i]) {
      l = 0;
      dfs(i, -1);
      god = i;
      if (dfs2(i, -1, 0)) {
        ++ct;
      }
    }
  }
  cout << ct << endl;
}
