﻿using System;

//Print to stdout the largest prime palindrome less than 1000.

namespace Palindrome
{
  class Palindrome
  {
    public static Boolean FindPalindrome(String original)
    {
      String reverse = "";

      int length = original.Length;

      for (int i = length - 1; i >= 0; i--)
      {
        reverse = reverse + original[i];
      }
      if (reverse.Equals(original))
        return true;
      return false;
    }
    public static Boolean Prime(int number)
    {
      for (int i = 2; i <= number / 2; i++)
      {
        if (number % i == 0)
        {
          return false;
        }
      }
      return true;
    }
    static void Main(string[] args)
    {
      int original = 1000;

      while (original > 0)
      {
        if (FindPalindrome(original.ToString()) && Prime(original))
        {
          Console.WriteLine(original);
          break;
        }
        original--;
      }
    }
  }
}