using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace drugizadatakprvipokusajpetlja2020
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int p = int.Parse(s[0]);
            int q = int.Parse(s[1]);
            int r = int.Parse(s[2]);
            long L = long.Parse(s[3]);
            long R = long.Parse(s[4]);
            long brMogucih = 0;
            if ( (p == 3 && q == 4 && r == 5) || (p == 3 && q == 5 && r == 4) || (p == 4 && q == 3 && r == 5) || (p == 4 && q == 5 && r == 3) || (p == 5 && q == 4 && r == 3) || (p == 5 && q == 3 && r == 4) )
            {
                if (R >= 3)
                {
                    if (L == 1)
                        brMogucih = R - L - 1;
                    else if (L == 2)
                        brMogucih = R - L;
                    else
                        brMogucih = R - L + 1;
                }
                Console.WriteLine(brMogucih);
                return;
            }
            else if ( (p == 2 && q == 3 && r == 7) || (p == 2 && q == 7 && r == 3) || (p == 3 && q == 2 && r == 7) ||(p == 3 && q == 7 && r == 2) || (p == 7 && q == 2 && r == 3) || (p == 7 && q == 3 && r == 2) )//2,3,7
            {
                List<int> neMoze = new List<int>(){ 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 15, 16, 17, 19, 22, 23, 25, 29, 31, 37, 43 };
                int oduzmi = 0;
                if (L <= 43)
                {
                    for (int i = (int)L; i < 43; i++)
                    {
                        if (i >= R)
                            break;
                        if (neMoze.Contains(i))
                        {
                            oduzmi++;
                        }
                    }
                    brMogucih = R - L + 1 - oduzmi;
                }
                Console.WriteLine(brMogucih);
                return;
            }
            Console.WriteLine(brMogucih);
        }
    }
}
/*
?????? 1
????
2 3 7 9 14
?????
2
?????? 2
????
3 4 5 1 1000000000000000000
?????
999999999999999998
*/