#include <stdio.h>
#include <math.h>

int prime(int num) {
    int i;
    if (num <= 1)
        return 0;
    if (num == 2)
        return 1;
    if (num % 2 == 0)
        return 0;

    for (i = 3; i <= sqrt(num); i += 2) {
        if (num % i == 0)
            return 0;
    }

    return 1;
}

int reverse(int num) {
    int reversedNum = 0;
    while (num > 0) {
        reversedNum = reversedNum * 10 + num % 10;
        num /= 10;
    }
    return reversedNum;
}

int main() {
    int m, n;
    int i;

    scanf("%d %d", &m, &n);
    
    for (i = m; i <= n; i++) {
        if (prime(i) && prime(reverse(i)))
            printf("%d\n", i);
    }
    
    return 0;
}
