#include <bits/stdc++.h>
using namespace std;
template <typename T>
T read() {
  T p = 1, x = 0;
  char s = getchar();
  while (s == ' ' || s == '\n') s = getchar();
  if (s == '-') p = -1, s = getchar();
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * p;
}
template <typename A, typename B>
void Umax(A &a, const B &b) {
  if (a < b) a = b;
}
template <typename A, typename B>
void Umin(A &a, const B &b) {
  if (a > b) {
    a = b;
  }
}
long long bin_pow(long long a, long long n) {
  if (n == 0) {
    return 1;
  }
  if (n % 2 == 1) {
    long long cnt = a * bin_pow(a, n - 1);
    return cnt;
  } else {
    long long cnt = bin_pow(a, n / 2);
    return cnt * cnt;
  }
}
const int N = (int)1e6 + 10;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
int n, m;
int used[N];
int used2[N];
vector<int> g[N];
bool f = 0, q = 0;
void dfs(int v) {
  used[v] = 1;
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (used[to] == 1) {
      f = 1;
    }
    if (used[to] == 0) {
      dfs(to);
    }
  }
  used[v] = 2;
}
void dfs2(int v) {
  used2[v] = 1;
  if (g[v].size() != 2) {
    q = 1;
  }
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (used2[to] == 0) {
      dfs2(to);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (used[i] == 0) {
      dfs(i);
      if (f) {
        dfs2(i);
        if (!q) {
          ans++;
        }
      }
    }
    q = 0;
    f = 0;
  }
  cout << ans << endl;
  return 0;
}
