#include <bits/stdc++.h>
void read();
const int N = 1e5 + 100;
const int M = 2e5 + 100;
const long long oo = 1e18;
using namespace std;
vector<vector<int>> v;
int vis[M];
int first = 0;
int lasN = -1;
void dfs(int cur, int las) {
  vis[cur] = true;
  if (first) first = -1;
  for (int i = 0; i < v[cur].size(); i++) {
    if (!vis[v[cur][i]])
      dfs(v[cur][i], cur);
    else if (v[cur][i] != las && !first)
      first = 1, lasN = cur;
    else if (v[cur][i] != las && first == 1 && v[cur][i] != lasN)
      first = -1;
  }
  if (!first) first = -1;
}
int main() {
  int n, m;
  cin >> n >> m;
  v.resize(n);
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    r--, l--;
    v[l].push_back(r);
    v[r].push_back(l);
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    first = 0;
    lasN = -1;
    if (!vis[i]) {
      dfs(i, i);
    }
    if (first == 1) sum += 1;
  }
  cout << sum << endl;
  return 0;
}
void read() {
  freopen("in.txt", "r", stdin);
  freopen("ou.txt", "w", stdout);
}
