#include <bits/stdc++.h>
using namespace std;
const int BLOCK = 10000;
int nP[20000], B[BLOCK];
int P[20000], C;
int n, m;
int solve(int n1, int n) {
  C = 0;
  for (int i = 2; i * i <= n; ++i)
    if (!nP[i]) {
      P[C++] = i;
      for (int j = i + i; j * j <= n; j += i) nP[j] = 1;
    }
  int res = 0;
  for (int k = 0, mxk = n / BLOCK; k <= mxk; ++k) {
    memset(B, 0, sizeof(B));
    int beg = k * BLOCK;
    for (int i = 0; i < C; ++i)
      for (int j = max((beg + P[i] - 1) / P[i], 2) * P[i] - beg; j < BLOCK;
           j += P[i])
        B[j] = 1;
    if (!k) B[0] = B[1] = 1;
    int x = beg;
    for (int i = 0; i < BLOCK && beg + i <= n; ++i) {
      if (!B[i] && x >= n1 && ((x & 3) == 1 || x == 2)) ++res;
      ++x;
    }
  }
  return res;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    printf("%d\n", solve(n, m));
  }
  return 0;
}
