#include <bits/stdc++.h>
using namespace std;
vector<long long> g[2 * 100011];
bool p = 0;
bool mark[100011 * 2];
long long x = 0, y = 0;
void dfs(long long v) {
  if (mark[v]) return;
  mark[v] = 1;
  y += g[v].size();
  if (g[v].size() != 2) p = 1;
  for (long long i = 0; i < g[v].size(); i++) {
    long long u = g[v][i];
    if (mark[u]) continue;
    x++;
    dfs(u);
  }
}
int main() {
  long long n, m, ans = 0;
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    long long u, v;
    cin >> u >> v;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  for (long long i = 1; i <= n; i++) {
    if (mark[i]) continue;
    x = 0;
    y = 0;
    p = 0;
    dfs(i);
    y /= 2;
    x++;
    if (x == y and !p) ans++;
  }
  cout << ans;
}
