#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = INT_MAX;
const long long LINF = LLONG_MAX;
const int N = 2e5 + 20;
vector<int> g[N];
bool visited[N];
int n, m, ans;
bool dfs(int v) {
  visited[v] = 1;
  bool res = g[v].size() == 2;
  for (int u : g[v])
    if (!visited[u]) res &= dfs(u);
  return res;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0, v, u; i < m; i++) {
    cin >> v >> u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; i++)
    if (!visited[i]) ans += dfs(i);
  cout << ans << endl;
}
