#include <bits/stdc++.h>
using namespace std;
vector<long long> v1;
vector<long long>::iterator upper, lower, it;
vector<vector<long long>> adj(200005);
unordered_map<long long, long long> mp;
long long vis[200005] = {0};
long long sug = false;
void dfs(vector<vector<long long>> &v, long long child, long long parent) {
  long long i;
  for (i = 0; i < v[child].size(); i++) {
    if (v[child][i] == parent) {
      continue;
    }
    if (v[v[child][i]].size() != 2) {
      sug = false;
    } else {
      if (vis[v[child][i]] == 1) {
        sug = true;
      } else if (vis[v[child][i]] == 0) {
        vis[v[child][i]] = 1;
        dfs(v, v[child][i], child);
      }
    }
  }
}
void solve() {
  long long n = 0, m = 0, i = 0, j = 0, l = 0, r = 0, x = 0, y = 0, q = 0,
            z = 0, len = 0, k = 0, p = 0;
  long long a[200005] = {0}, b[200005] = {0}, c[200005] = {0}, d[200005] = {0};
  char s[300005], t[300005];
  vector<vector<long long>> v(200005);
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    if (v[i].size() == 2 && vis[i] == 0) {
      vis[i] = 1;
      sug = false;
      dfs(v, i, 0);
      if (sug) {
        ans++;
      }
    }
  }
  cout << ans;
}
bool imp = false;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  if (imp) cin >> t;
  while (t--) solve();
  return 0;
}
