import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
{
int a, b;
int number1, number2;
int counter = 0;
Scanner sc
= new Scanner
(System.
in); a = sc.nextInt();
b = sc.nextInt();
if(a > b) {
a += b;
b = a - b;
a -= b;
}
if (a == 1) counter--;
for (int i = a; i <= b; i++){
number1 = i;
boolean f1 = true;
boolean f2 = true;
for (int j = 2; j*j <= number1; j++){
f1 = ((number1%j)!=0);
if (!f1)
break;
}
if (f1){
number2 = 0;
while (number1 > 0) {
number2 = number2*10 + number1%10;
number1 /= 10;
}
for (int j = 2; j*j <= number2; j++){
f2 = ((number2%j)!=0);
if (!f2) break;
}
if (f2) counter++;
}
}
System.
out.
format("%d", counter
); }
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBNYWluIHsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCWludCBhLCBiOwogICAgCWludCBudW1iZXIxLCBudW1iZXIyOwoJICAgCWludCBjb3VudGVyID0gMDsKCQlTY2FubmVyIHNjID0gbmV3IFNjYW5uZXIoU3lzdGVtLmluKTsKCQlhID0gc2MubmV4dEludCgpOwoJCWIgPSBzYy5uZXh0SW50KCk7CgkJaWYoYSA+IGIpIHsKCQkJYSArPSBiOwoJCQliID0gYSAtIGI7CgkJCWEgLT0gYjsKCQl9CgkJaWYgKGEgPT0gMSkgY291bnRlci0tOwoJCWZvciAoaW50IGkgPSBhOyBpIDw9IGI7IGkrKyl7CgkJCW51bWJlcjEgPSBpOyAKCQkJYm9vbGVhbiBmMSA9IHRydWU7CgkJCWJvb2xlYW4gZjIgPSB0cnVlOwoJCQlmb3IgKGludCBqID0gMjsgaipqIDw9IG51bWJlcjE7IGorKyl7CQkJCQkKCQkJCWYxID0gKChudW1iZXIxJWopIT0wKTsKCQkJCWlmICghZjE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