#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>

using namespace std;

char a[1100016];
char b[1100016];

int main()
{
    int top,t;
    while(~scanf("%s%s",a,b))
    {
        if(strcmp(a,b)==0)
        {
            printf("=\n");
            continue;
        }
        int lena=strlen(a);
        int lenb=strlen(b);
        int x,y;
        x=y=0;
        for(int i=0; i<=max(lena,lenb); i++)
        {
            if(i<=lena&&a[i]!='0'&&x==0)
            {
                t=i;
                x=1;
            }
            if(i<=lenb&&b[i]!='0'&&y==0)
            {
                top=i;
                y=1;
            }
        }
        //cout<<t<<" "<<top<<endl;
        lena=lena-t;
        lenb=lenb-top;
        if(lena==0)
        {
            if(lenb!=0)printf("<\n");
            else  printf("=\n");
            continue;
        }
        if(lenb==0)
        {
            if(lena!=0) printf(">\n");
            else  printf("=\n");
            continue;
        }
        if(lena<lenb)
        {
            printf("<\n");
        }
        else if(lena>lenb)
        {
             printf(">\n");
        }
        else
        {
            int f=0;
            for(int i=t,j=top; i<lena&&j<lenb; i++,j++)
            {
                if(a[i]>b[j])
                {
                     printf(">\n");
                    f=1;
                    break;
                }
                if(a[i]<b[j])
                {
                    printf("<\n");
                    f=1;
                    break;
                }
            }
            if(f==0) printf("=\n");
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int i,n,m;
    char a[200000],b[200000],*ap,*bp;
    scanf("%s",a);
    scanf("%s",b);
    n=strlen(a);
    m=strlen(b);
    ap=a;
    bp=b;
    for(i=0;i<n;i++)
    {
        if(*ap=='0')
            ap++;
        else
            break;
    }
    n=n-i;
    for(i=0;i<m;i++)
    {
        if(*bp=='0')
            bp++;
        else
            break;
    }
    m=m-i;
    if(n>m)
        printf(">\n");
    else if(n<m)
        printf("<\n");
    else
    {
        while((*ap)!='\0'&&(*bp)!='\0')
        {
            if((*ap)>(*bp))
            {
                printf(">\n");
                return 0;
            }
            else if((*ap)<(*bp))
            {
                printf("<\n");
                return 0;
            }
            else
            {
                ap++;
                bp++;
            }
        }
        printf("=\n");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

int main()
{
   char str1[10000],str2[10000];

   int L1,L2,i,j;
   while(~scanf("%s\n",str1))
   {
       i=j=0;
       scanf("%s",str2);
       L1=strlen(str1);
       L2=strlen(str2);
       for(i=0;i<L1;i++)
       {
           if(str1[i]!='0')
            break;
       }
       for(j=0;j<L2;j++)
       {
           if(str2[j]!='0')
            break;
       }
       if((L1-i)>(L2-j))
            printf(">\n");
       else if((L1-i)>(L2-j))
            printf("<\n");
       else
       {
           while(i<L1&&j<L2)
           {
               if(str1[i]>str2[j])
               {
                   printf(">\n");
                   break;
               }
               if(str1[i]<str2[j])
               {
                   printf("<\n");
                   break;
               }
               if(str1[i]==str2[j])
               {
                   i++;
                   j++;
               }
           }
           if(i==L1&&j==L2)
            printf("=\n");
       }
   }
    return 0;
}


#include<stdio.h>
#include<string.h>
char a[20],b[20];
int n,m;
int main()
{
    int len1,len2;
    while(~scanf("%s",a))
    {
        scanf("%s",b);
        int i,j,k,t;
        int e;
        n = m = 0;
        len1 = strlen(a);
        len2 = strlen(b);
        for(i = 0;i < len1;i++)
        {
            if(a[i] != '0')
                break;
        }
        t = 1;
        for(k = len1-1;k >= i;k--)
        {
            e = a[k] - '0';
            n += e*t;
            t = t*10;
        }
        for(j = 0;j < len2;j++)
        {
            if(b[j] != '0')
                break;
        }
        t = 1;
        for(k = len2-1;k >= j;k--)
        {
            e = b[k] - '0';
            m += e*t;
            t = t*10;
        }
        if(n > m)
            printf(">\n");
        else if(n < m)
            printf("<\n");
        else if(n == m)
            printf("=\n");
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int a,b;
    scanf("%lld%lld",&a,&b);
    if(a>b)
        printf(">\n");
    else if(a==b)
        printf("=\n");
    else
        printf("<\n");
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

char a[1000000], b[1000000];

void ss(char a, char b)
{
    if(a == b)
        cout<<'='<<endl;
    else if(a < b)
        cout<<'<'<<endl;
    else
        cout<<'>'<<endl;
}

int main()
{
    while(~scanf("%s%s",a,b))
    {
        int l1 = strlen(a);
        int l2 = strlen(b);
        int i = 0, j = 0;
        while(a[i] == '0')
            i++;
        while(b[j] == '0')
            j++;
     //   cout<<l1<<' '<<i<<l2<<' '<<j<<endl;
        if(l1-i < l2 - j)
        cout<<'<'<<endl;
        else if(l1-i > l2-j)
        cout<<'>'<<endl;
        else
        {
        //    cout<<'#'<<endl;
            while(i<l1 && j<l2)
            {
                if(a[i] == b[j])
                    {i++,j++;continue;}
                else
                    {ss(a[i],b[j]);break;}
            }
            if(i == l1&&j == l2)
                cout<<'='<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
char a[1123456],b[123456];

int main()
{
        scanf("%s%s",&a,&b);
        long long int top1=0,top2=0,len1=strlen(a),len2=strlen(b);
        while(a[top1]=='0') top1++;
        while(b[top2]=='0') top2++;
      //  if(len1-top1>len2-top2) printf(">\n");
       // else if(len1-top1<len2-top2) printf("<\n");
            int flag=1;
         //   cout<<top1<<" "<<len1<<" "<<top2<<" "<<len2<<endl;
            while(top1<len1&&top2<len2)
            {
               // cout<<a[top1]<<" "<<b[top2]<<endl;
                if(a[top1]=='.'&&b[top2]!='.')
                {
                    flag=0;
                    printf("<\n");
                    break;
                }
                else if(a[top1]!='.'&&b[top2]=='.')
                {
                    flag=0;
                    printf(">\n");
                    break;
                }
            //    else if(a[top1]=='.'&&b[top2]=='.') continue;
                else if(a[top1]>b[top2])
                {
                    flag=0;
                    printf(">\n");
                    break;
                }
                else if(a[top1]<b[top2])
                {
                    flag=0;
                    printf("<\n");
                    break;
                }
                top1++;
                top2++;
            }
           // cout<<"22";
            if(flag) printf("=\n");

    return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
char a[1123456],b[123456];

int main()
{

       while(~scanf("%s%s",&a,&b))
       {
        long long int top1=0,top2=0,len1=strlen(a),len2=strlen(b);
        while(a[top1]=='0')
        {
            if(top1>=len1) break;
            top1++;
            if(top1>=len1) break;
        }
        while(b[top2]=='0')
        {
            if(top2>=len2) break;
            top2++;
            if(top2>=len2) break;
        }
        if(len1-top1>len2-top2) printf(">\n");
        else if(len1-top1<len2-top2) printf("<\n");
        else
        {
            int flag=1;
            while(top1<len1&&top2<len2)
            {
               // cout<<a[top1]<<" "<<b[top2]<<endl;
                if(a[top1]>b[top2])
                {
                    flag=0;
                    printf(">\n");
                    break;
                }
                else if(a[top1]<b[top2])
                {
                    flag=0;
                    printf("<\n");
                    break;
                }
                top1++;
                top2++;
            }
            if(flag) printf("=\n");
        }
       }

    return 0;
}


#include<stdio.h>
#include<string.h>
#define N 1000005
char a[N],b[N];
int n,m;
int main()
{
    int l1,l2;
    while(~scanf("%s %s",a,b))
    {
        int i,j,p,q;
        n = m = 0;
        int e;
        int k = 1,l = 1;
        l1 = strlen(a);
        l2 = strlen(b);
        for(i = 0;i < l1;i++)
        {
            if(a[i] != '0')
                break;
        }
        for(p = l1-1;p >= i;p--)
        {
             e = a[p] - '0';
             n += e*k;
             k = k*10;
        }
        for(j = 0;j < l2;j++)
        {
            if(b[j] != '0')
                break;
        }
        for(q = l2-1;q >= j;q--)
        {
            e = b[q] - '0';
            m += e*l;
            l = l*10;
        }
        if(n > m)
        {
            printf(">\n");
        }
        else if(n < m)
        {
            printf("<\n");
        }
        else if(n == m)
        {
            printf("=\n");
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

int main()
{
   char s1[10000000],s2[10000000];

   int L1,L2,i,j;
   while(~scanf("%s",s1))
   {
       i=j=0;
       scanf("%s",s2);
       L1=strlen(s1);
       L2=strlen(s2);
       for(i=0;i<L1;i++)
       {
           if(s1[i]!='0')
            break;
       }
       for(j=0;j<L2;j++)
       {
           if(s2[j]!='0')
            break;
       }
       if((L1-i)>(L2-j))
            printf(">\n");
       else if((L1-i)<(L2-j))
            printf("<\n");
       else
       {
           while(i<L1&&j<L2)
           {
               if(s1[i]>s2[j])
               {
                   printf(">\n");
                   break;
               }
                if(s1[i]<s2[j])
               {
                   printf("<\n");
                   break;
               }
               if(s1[i]==s2[j])
               {
                   i++;
                   j++;
               }
           }
           if(i==L1&&j==L2)
            printf("=\n");
       }
   }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#define mod 10000007
char a[1000005],b[1000005];
int main()
{
    long long x,y;
    int i,j;
   while(~scanf("%s",a))
   {

       scanf("%s",b);
       int len = strlen(a);
       int len1= strlen(b);
       int count = 0,count1=0;
      for(i=0;i<len;i++)
      {
          if(a[i]!='0')
            break;
      }
      count=i;
      for(i=0;i<len;i++)
      {
          if(b[i]!='0')
            break;
      }
      count1 = i;
      if(len - count >len1-count1)
      {
          printf(">\n");
      }
      else if(len - count <len1-count1)
      {
          printf("<\n");
      }
      else
      {
          for(i=count,j=count1;i<len;i++,j++)
          {
              if(a[i]-'0'>b[j]-'0')
              {
                  printf(">\n");break;
              }
              else if((a[i]-'0'<b[j]-'0'))
              {
                  printf("<\n");break;
              }
          }
          if(i==len)
          {
              printf("=\n");
          }
      }

   }
   return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;

int main()
{
    char n[1000005], m[1000005];
    scanf ( "%s", n );
    scanf ( "%s", m );
    int i = 0;
    while ( n[i] == '0' )
    {
        i++;
    }
    int len1 = strlen(n)-i;
    int j = 0;
    while ( m[j] == '0' )
    {
        j++;
    }
    int len2 = strlen(m)-j;
    if ( len1 > len2 )
    {
        printf ( ">\n" );
    }
    else if (len1 < len2)
    {
        printf ( "<\n");
    }
    else
    {
        int ok = 0;
        while ( n[i] == m[j] )
        {
            i++;
            j++;
            if ( i == len1-1 )
                break;
        }
        if ( n[i] > m[j] )
        {
            printf ( ">\n" );
        }
        else if (n[i] < m[j])
        {
            printf ( "<\n");
        }
        else
            printf ( "=\n" );
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn=1000010;

int main()
{
    char s1[maxn];
    char s2[maxn];
    int i,j,k;
    int k1,k2;
    while (cin>>s1>>s2)
    {
        for (i=0; s1[i]; i++)
        {
            if (s1[i]!='0')
            {
                break;
            }
        }

        for (j=0; s2[j]; j++)
        {
            if (s2[j]!='0')
            {
                break;
            }
        }
        k1=strlen(s1);
        k2=strlen(s2);
        if (k1-i > k2-j)
        {
            cout<<">"<<endl;
        }
        else if (k1-i < k2-j)
        {
            cout<<"<"<<endl;
        }
        else if  (k1-i == k2-j)
        {
            while (i<k1)
            {
                if (s1[i]>s2[j])
                {
                    cout<<">"<<endl;
                    break;
                }
                else if (s1[i]<s2[j])
                {
                    cout<<"<"<<endl;
                    break;
                }
                else
                {
                    i++;
                    j++;
                }
            }
            if (i>=k1)
            {
                cout<<"="<<endl;
            }
        }

    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#define N 10
char a[N],b[N];
long long int n,m;
int main()
{
    int l1,l2;
    while(~scanf("%s %s",a,b))
    {
        int i,j,p,q;
        n = m = 0;
        int e;
        int k = 1,l = 1;
        l1 = strlen(a);
        l2 = strlen(b);
        for(i = 0;i < l1;i++)
        {
            if(a[i] != '0')
                break;
        }
        for(p = l1-1;p >= i;p--)
        {
             e = a[p] - '0';
             n += e*k;
             k = k*10;
        }
        for(j = 0;j < l2;j++)
        {
            if(b[j] != '0')
                break;
        }
        for(q = l2-1;q >= j;q--)
        {
            e = b[q] - '0';
            m += e*l;
            l = l*10;
        }
        if(n > m)
        {
            printf(">\n");
        }
        else if(n < m)
        {
            printf("<\n");
        }
        else if(n == m)
        {
            printf("=\n");
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
char a[1001000], b[1001000];
int main()
{
    scanf("%s", a);
    scanf("%s", b);
    int l1 = strlen(a);
    int l2 = strlen(b);
    long long int s=0, t=0;
    for(int i = 0; i < l1; i++)
    {
        if(a[i] != '0')
        {
            for(int j = i; j < l1; j++)
            {
                s = a[j]-'48'+s*10;
            }
            break;
        }
    }
    for(int i = 0; i < l2; i++)
    {
        if(b[i] != '0')
        {
            for(int j = i; j < l2; j++)
            {
                t = b[j]-'48'+t*10;
            }
            break;
        }
    }
    if(s > t)
        printf(">\n");
    else if(s < t)
        printf("<\n");
    else
        printf("=\n");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

char s[1000010], a[1000010];
int sum[1000010];

int main()
{
    while (~scanf("%s %s", s, a))
    {
        memset(sum, 0, sizeof(sum));
        while (s[0] == '0')
        {
            for (int i = 0; i < strlen(s); i++)
                s[i] = s[i + 1];
        }
        while (a[0] == '0')
        {
            for (int i = 0; i < strlen(a); i++)
                a[i] = a[i + 1];
        }
        int l1 = strlen(s), l2 = strlen(a);
        if (l1 == l2)
        {
            int i = 0, j = 0;
            int f = 1;
            while (i < l1 && j < l2)
            {
                if (s[i] == a[j])
                {
                    i++;
                    j++;
                }
                else if (s[i] > a[j])
                {
                    printf(">\n");
                    f = 0;
                    break;
                }
                else if (s[i] < a[j])
                {
                    printf("<\n");
                    f = 0;
                    break;
                }
            }
            if (f)
                printf("=\n");
        }
        else if (l1 > l2)
        printf(">\n");
        else if (l1 < l2)
            printf("<\n");
    }
    return 0;
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMaximumValue solver = new BMaximumValue();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMaximumValue {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int[] ar = new int[n];
            int[] max = new int[2000002];
            boolean[] checker = new boolean[2000002];
            for (int i = 0; i < n; i++) checker[ar[i] = in.scanInt()] = true;
            max[0] = -1;
            for (int i = 1; i < 2000001; i++)
                if (checker[i]) max[i] = i;
                else max[i] = max[i - 1];
            long ans = 0;
            for (int i = 1; i <= 2000000; i++) {
                if (!checker[i]) continue;
                for (int j = i - 1; j <= 2000000; j += i) {
                    if (max[j] >= i) {
                        ans = Math.max(ans, max[j] % i);
                    }
                }
            }
            out.println(ans);

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMaximumValue solver = new BMaximumValue();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMaximumValue {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int[] ar = new int[n];
            int[] small = new int[1000001];
            for (int i = 0; i < n; i++) ar[i] = in.scanInt();
            for (int i : ar) small[i] = i;
            for (int i = 1; i < 1000001; i++) small[i] = Math.max(small[i], small[i - 1]);
            int ans = 0;
            for (int i = 2; i < 1000001; i++) {
                if (small[i] == i) {
                    for (int j = i + i - 1; j < 1000001; j += i) if (small[j] >= i) ans = Math.max(ans, small[j] % i);
                }
            }
            out.println(ans);

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMaximumValue solver = new BMaximumValue();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMaximumValue {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int[] ar = new int[n];
            int[] small = new int[1000001];
            for (int i = 0; i < n; i++) ar[i] = in.scanInt();
            for (int i : ar) small[i] = i;
            for (int i = 1; i < 1000001; i++) small[i] = Math.max(small[i], small[i - 1]);
            int ans = 0;
            for (int i = 2; i < 1000001; i++) {
                if (small[i] == i) {
                    for (int j = i + i - 1; j < 1000001; j += i) ans = Math.max(ans, small[j] % i);
                    ans = Math.max(ans, small[1000000] % i);
                }
            }
            out.println(ans);

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMaximumValue solver = new BMaximumValue();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMaximumValue {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int[] ar = new int[n];
            int[] max = new int[1000002];
            boolean[] checker = new boolean[1000002];
            for (int i = 0; i < n; i++) checker[ar[i] = in.scanInt()] = true;
            max[0] = -1;
            for (int i = 1; i < 1000001; i++)
                if (checker[i]) max[i] = i;
                else max[i] = max[i - 1];
            long ans = 0;
            for (int i = 1; i <= 1000000; i++) {
                if (!checker[i]) continue;
                for (int j = i - 1; j <= 1000000; j += i) {
                    if (max[j] >= i) {
                        ans = Math.max(ans, max[j] % i);
                    }
                }
            }
            out.println(ans);

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}


/*
 *
 * @author Mukesh Singh
 *
 */

import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
@SuppressWarnings("unchecked")
public class AB {

	//solve test cases
	void solve() throws Exception {
		int n = in.nextInt();
		int max = 10;
		boolean[] ar= new boolean[2*max+1];
		int[] br= new int[2*max+1];
		for(int i = 0 ; i < n ; ++i) {
			ar[in.nextInt()] = true ;
		}
		int ans = 0 ;
		for(int i = 1 ; i <= 2*max ; ++i)
			if(ar[i]) br[i] = i ;
			else br[i] = br[i-1] ;
		for(int i = 0 ; i <= 2*max ; ++i){
			if(ar[i]){
				for(int aj = i ; aj <= 2*max ; aj+=i){
					int ai = br[aj] ;
					//System.out.println(ai+" "+i);
					if(ai > i) ans = Math.max(ans,ai%i);
				}
			}
		}
		System.out.println(ans);
	}

	//@ main function
	public static void main(String[] args) throws Exception {
		new AB();
	}

	InputReader in;
	PrintStream out ;
	DecimalFormat df ;
	AB() {
		try {
			File defaultInput = new File("file.in");
			if (defaultInput.exists())
				in = new InputReader("file.in");
			else
				in = new InputReader();
			defaultInput = new File("file.out");
			if (defaultInput.exists())
				out = new PrintStream(new FileOutputStream("file.out"));
			else
				out = new PrintStream(System.out);
			df = new DecimalFormat("######0.00");
			solve();
			out.close();
		}
		catch (Exception e) {
			e.printStackTrace();
			System.exit(261);
		}
	}

	class InputReader {
		BufferedReader reader;
		StringTokenizer tokenizer;

		InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		InputReader(String fileName) throws FileNotFoundException {
			reader = new BufferedReader(new FileReader(new File(fileName)));
		}

		String readLine() throws IOException {
			return reader.readLine();
		}

		String nextToken() throws IOException {
			while (tokenizer == null || !tokenizer.hasMoreTokens())
				tokenizer = new StringTokenizer(readLine());
			return tokenizer.nextToken();
		}

		boolean hasMoreTokens() throws IOException {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				String s = readLine();
				if (s == null)
					return false;
				tokenizer = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(nextToken());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(nextToken());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(nextToken());
		}
	}
}


/*
 *
 * @author Mukesh Singh
 *
 */

import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
@SuppressWarnings("unchecked")
public class AB {

	//solve test cases
	void solve() throws Exception {
		int n = in.nextInt();
		int max = 1000000;
		boolean[] ar= new boolean[2*max+10];
		int[] br= new int[2*max+10];
		for(int i = 0 ; i < n ; ++i) {
			ar[in.nextInt()] = true ;
		}
		int ans = 0 ;
		for(int i = 1 ; i <= 2*max ; ++i)	{
			if(ar[i]) br[i] = i ;
			else br[i] = br[i-1] ;
		}
		for(int i = 1 ; i <= max ; ++i){
			if(ar[i]){
				for(int aj = i ; aj <= 2*max ; aj+=i){
					int ai = br[aj] ;
					//System.out.println(ai+" "+i);
					if(ai > i) ans = Math.max(ans,ai%i);
					ai = br[aj-1] ;
					//System.out.println(ai+" "+i);
					if(ai > i) ans = Math.max(ans,ai%i);
				}
			}
		}
		System.out.println(ans);
	}

	//@ main function
	public static void main(String[] args) throws Exception {
		new AB();
	}

	InputReader in;
	PrintStream out ;
	DecimalFormat df ;
	AB() {
		try {
			File defaultInput = new File("file.in");
			if (defaultInput.exists())
				in = new InputReader("file.in");
			else
				in = new InputReader();
			defaultInput = new File("file.out");
			if (defaultInput.exists())
				out = new PrintStream(new FileOutputStream("file.out"));
			else
				out = new PrintStream(System.out);
			df = new DecimalFormat("######0.00");
			solve();
			out.close();
		}
		catch (Exception e) {
			e.printStackTrace();
			System.exit(261);
		}
	}

	class InputReader {
		BufferedReader reader;
		StringTokenizer tokenizer;

		InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		InputReader(String fileName) throws FileNotFoundException {
			reader = new BufferedReader(new FileReader(new File(fileName)));
		}

		String readLine() throws IOException {
			return reader.readLine();
		}

		String nextToken() throws IOException {
			while (tokenizer == null || !tokenizer.hasMoreTokens())
				tokenizer = new StringTokenizer(readLine());
			return tokenizer.nextToken();
		}

		boolean hasMoreTokens() throws IOException {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				String s = readLine();
				if (s == null)
					return false;
				tokenizer = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(nextToken());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(nextToken());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(nextToken());
		}
	}
}


/*
 *
 * @author Mukesh Singh
 *
 */

import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
@SuppressWarnings("unchecked")
public class AB {

	//solve test cases
	void solve() throws Exception {
		int n = in.nextInt();
		int max = 1000000;
		boolean[] ar= new boolean[2*max+1];
		int[] br= new int[2*max+1];
		for(int i = 0 ; i < n ; ++i) {
			ar[in.nextInt()] = true ;
		}
		int ans = 0 ;
		for(int i = 1 ; i <= 2*max ; ++i)
			if(ar[i]) br[i] = i ;
			else br[i] = br[i-1] ;
		for(int i = 0 ; i <= 2*max ; ++i){
			if(ar[i]){
				for(int aj = i ; aj <= 2*max ; aj+=i){
					int ai = br[aj] ;
					//System.out.println(ai+" "+i);
					if(ai > i) ans = Math.max(ans,ai%i);
				}
			}
		}
		System.out.println(ans);
	}

	//@ main function
	public static void main(String[] args) throws Exception {
		new AB();
	}

	InputReader in;
	PrintStream out ;
	DecimalFormat df ;
	AB() {
		try {
			File defaultInput = new File("file.in");
			if (defaultInput.exists())
				in = new InputReader("file.in");
			else
				in = new InputReader();
			defaultInput = new File("file.out");
			if (defaultInput.exists())
				out = new PrintStream(new FileOutputStream("file.out"));
			else
				out = new PrintStream(System.out);
			df = new DecimalFormat("######0.00");
			solve();
			out.close();
		}
		catch (Exception e) {
			e.printStackTrace();
			System.exit(261);
		}
	}

	class InputReader {
		BufferedReader reader;
		StringTokenizer tokenizer;

		InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		InputReader(String fileName) throws FileNotFoundException {
			reader = new BufferedReader(new FileReader(new File(fileName)));
		}

		String readLine() throws IOException {
			return reader.readLine();
		}

		String nextToken() throws IOException {
			while (tokenizer == null || !tokenizer.hasMoreTokens())
				tokenizer = new StringTokenizer(readLine());
			return tokenizer.nextToken();
		}

		boolean hasMoreTokens() throws IOException {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				String s = readLine();
				if (s == null)
					return false;
				tokenizer = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(nextToken());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(nextToken());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(nextToken());
		}
	}
}


/*
 *
 * @author Mukesh Singh
 *
 */

import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
@SuppressWarnings("unchecked")
public class AB {

	//solve test cases
	void solve() throws Exception {
		int n = in.nextInt();
		int[] ar= new int[n];
		int max = 0 ;
		TreeSet<Integer> ts = new TreeSet<>();
		for(int i = 0 ; i < n ; ++i) {
			ar[i] = in.nextInt();
			if(ar[i] > max ) max = ar[i] ;
			ts.add(ar[i]);
		}
		int ans = 0 ;
		for(int i = 0 ; i < n ; ++i){
			int aj = ar[i] ;
			int temp = aj ;
			while(temp <= 2*max){
				Integer ob = ts.lower(temp);
				temp+= aj ;
				if(ob != null){
					int ai = ob ;
					int aa = 0 ;
					if(ai>aj) aa = ai%aj ;
					//System.out.println(ai+" "+aj+" "+aa);
					ans = Math.max(ans,aa);
				}
			}
		}
		System.out.println(ans);
	}

	//@ main function
	public static void main(String[] args) throws Exception {
		new AB();
	}

	InputReader in;
	PrintStream out ;
	DecimalFormat df ;
	AB() {
		try {
			File defaultInput = new File("file.in");
			if (defaultInput.exists())
				in = new InputReader("file.in");
			else
				in = new InputReader();
			defaultInput = new File("file.out");
			if (defaultInput.exists())
				out = new PrintStream(new FileOutputStream("file.out"));
			else
				out = new PrintStream(System.out);
			df = new DecimalFormat("######0.00");
			solve();
			out.close();
		}
		catch (Exception e) {
			e.printStackTrace();
			System.exit(261);
		}
	}

	class InputReader {
		BufferedReader reader;
		StringTokenizer tokenizer;

		InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		InputReader(String fileName) throws FileNotFoundException {
			reader = new BufferedReader(new FileReader(new File(fileName)));
		}

		String readLine() throws IOException {
			return reader.readLine();
		}

		String nextToken() throws IOException {
			while (tokenizer == null || !tokenizer.hasMoreTokens())
				tokenizer = new StringTokenizer(readLine());
			return tokenizer.nextToken();
		}

		boolean hasMoreTokens() throws IOException {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				String s = readLine();
				if (s == null)
					return false;
				tokenizer = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(nextToken());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(nextToken());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(nextToken());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class bSolution{
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String args[]){
		int n = Integer.parseInt(next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(next());
		}
		int curr = 0;
		Arrays.sort(a);
		int max = 2*a[n-1];
		int[] arr = generateOrderArray(a);
		int currVal;
		int prev = 0;
		for (int j = 0; j < n; j++){
			if (a[j] == prev){
				continue;
			}
			for(int check = 2*a[j]; check < max; check += a[j]){
				if (arr[check] < check - a[j] && check != 2*a[j]){
					continue;
				}
				currVal = arr[check] - (check - a[j]);
				if (currVal > curr){
					curr = currVal;
				}
				check += a[j];
			}
			prev = a[j];
		}
		System.out.println(curr);
	}

	private static StringTokenizer st;

	private static String next(){
		while (st == null || !st.hasMoreElements()){
			String str;
			try{
				str = br.readLine();
			} catch (IOException e){
				return null;
			}
			st = new StringTokenizer(str);
		}
		return st.nextToken();
	}

	private static int[] generateOrderArray(int[] a){
		int max = 2*a[a.length-1];
		int[] arr = new int[max];
		int aPointer = a.length-1;
		for (int i = max-1; i >= 0; i--){
			while(aPointer >= 0 && a[aPointer] >= i){
				aPointer--;
			}
			if (aPointer == -1){
				arr[i] = -1;
			} else {
				arr[i] = a[aPointer];
			}
		}
		return arr;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class bSolution{
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String args[]){
		int n = Integer.parseInt(next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(next());
		}
		int curr = 0;
		Arrays.sort(a);
		int max = 2*a[n-1];
		int[] arr = generateOrderArray(a);
		int currVal;
		int prev = 0;
		for (int j = 0; j < n; j++){
			if (a[j] == prev){
				continue;
			}
			for(int check = 2*a[j]; check < max; check += a[j]){
				if (arr[check] == arr[check-a[j]] && check != 2*a[j]){
					continue;
				}
				currVal = arr[check] - (check - a[j]);
				if (currVal > curr){
					curr = currVal;
				}
				check += a[j];
			}
			prev = a[j];
		}
		System.out.println(curr);
	}

	private static StringTokenizer st;

	private static String next(){
		while (st == null || !st.hasMoreElements()){
			String str;
			try{
				str = br.readLine();
			} catch (IOException e){
				return null;
			}
			st = new StringTokenizer(str);
		}
		return st.nextToken();
	}

	private static int[] generateOrderArray(int[] a){
		int max = 2*a[a.length-1];
		int[] arr = new int[max];
		int aPointer = a.length-1;
		for (int i = max-1; i >= 0; i--){
			while(aPointer >= 0 && a[aPointer] >= i){
				aPointer--;
			}
			if (aPointer == -1){
				arr[i] = -1;
			} else {
				arr[i] = a[aPointer];
			}
		}
		return arr;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class bSolution{
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String args[]){
		int n = Integer.parseInt(next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(next());
		}
		int curr = 0;
		Arrays.sort(a);
		int max = 2*a[n-1];
		int[] arr = generateOrderArray(a);
		int currVal;
		for (int j = 0; j < n; j++){
			for(int check = 2*a[j]; check < max; check += a[j]){
				if (arr[check] == arr[check-a[j]]){
					continue;
				}
				currVal = arr[check] - (check - a[j]);
				if (currVal > curr){
					curr = currVal;
				}
				check += a[j];
			}
		}
		System.out.println(curr);
	}

	private static StringTokenizer st;

	private static String next(){
		while (st == null || !st.hasMoreElements()){
			String str;
			try{
				str = br.readLine();
			} catch (IOException e){
				return null;
			}
			st = new StringTokenizer(str);
		}
		return st.nextToken();
	}

	private static int[] generateOrderArray(int[] a){
		int max = 2*a[a.length-1];
		int[] arr = new int[max];
		int aPointer = a.length-1;
		for (int i = max-1; i >= 0; i--){
			while(aPointer >= 0 && a[aPointer] >= i){
				aPointer--;
			}
			if (aPointer == -1){
				arr[i] = -1;
			} else {
				arr[i] = a[aPointer];
			}
		}
		return arr;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class bSolution{
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String args[]){
		int n = Integer.parseInt(next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(next());
		}
		int curr = 0;
		Arrays.sort(a);
		int max = 2*a[n-1];
		int[] arr = generateOrderArray(a);
		int currVal;
		int prev = 0;
		int check;
		for (int j = 0; j < n; j++){
			if (a[j] == prev){
				continue;
			}
			for(check = 2*a[j]; check < max; check += a[j]){
				if (arr[check] < check - a[j] && check != 2*a[j]){
					continue;
				}
				currVal = arr[check] - (check - a[j]);
				if (currVal > curr){
					curr = currVal;
				}
			}
			if (arr[max-1] > a[j]){
				if (arr[max-1] - a[j] > curr){
					curr = arr[max-1] - a[j];
				}
			}
			prev = a[j];
		}
		System.out.println(curr);
	}

	private static StringTokenizer st;

	private static String next(){
		while (st == null || !st.hasMoreElements()){
			String str;
			try{
				str = br.readLine();
			} catch (IOException e){
				return null;
			}
			st = new StringTokenizer(str);
		}
		return st.nextToken();
	}

	private static int[] generateOrderArray(int[] a){
		int max = 2*a[a.length-1];
		int[] arr = new int[max];
		int aPointer = a.length-1;
		for (int i = max-1; i >= 0; i--){
			while(aPointer >= 0 && a[aPointer] >= i){
				aPointer--;
			}
			if (aPointer == -1){
				arr[i] = -1;
			} else {
				arr[i] = a[aPointer];
			}
		}
		return arr;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class bSolution{
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String args[]){
		int n = Integer.parseInt(next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(next());
		}
		int curr = 0;
		Arrays.sort(a);
		int max = 2*a[n-1];
		int[] arr = generateOrderArray(a);
		int currVal;
		int prev = 0;
		for (int j = 0; j < n; j++){
			if (a[j] == prev){
				continue;
			}
			for(int check = 2*a[j]; check < max; check += a[j]){
				if (arr[check] == arr[check-a[j]]){
					continue;
				}
				currVal = arr[check] - (check - a[j]);
				if (currVal > curr){
					curr = currVal;
				}
				check += a[j];
			}
			prev = a[j];
		}
		System.out.println(curr);
	}

	private static StringTokenizer st;

	private static String next(){
		while (st == null || !st.hasMoreElements()){
			String str;
			try{
				str = br.readLine();
			} catch (IOException e){
				return null;
			}
			st = new StringTokenizer(str);
		}
		return st.nextToken();
	}

	private static int[] generateOrderArray(int[] a){
		int max = 2*a[a.length-1];
		int[] arr = new int[max];
		int aPointer = a.length-1;
		for (int i = max-1; i >= 0; i--){
			while(aPointer >= 0 && a[aPointer] >= i){
				aPointer--;
			}
			if (aPointer == -1){
				arr[i] = -1;
			} else {
				arr[i] = a[aPointer];
			}
		}
		return arr;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class bSolution{
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String args[]){
		int n = Integer.parseInt(next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(next());
		}
		int curr = 0;
		Arrays.sort(a);
		int max = 2*a[n-1];
		int[] arr = generateOrderArray(a);
		int check;
		int currVal;
		for (int j = 0; j < n; j++){
			check = 2*a[j];
			while(check < max){
				currVal = arr[check] - (check - a[j]);
				if (currVal > curr){
					curr = currVal;
				}
				check += a[j];
			}
		}
		System.out.println(curr);
	}

	private static StringTokenizer st;

	private static String next(){
		while (st == null || !st.hasMoreElements()){
			String str;
			try{
				str = br.readLine();
			} catch (IOException e){
				return null;
			}
			st = new StringTokenizer(str);
		}
		return st.nextToken();
	}

	private static int[] generateOrderArray(int[] a){
		int max = 2*a[a.length-1];
		int[] arr = new int[max];
		int aPointer = a.length-1;
		for (int i = max-1; i >= 0; i--){
			while(aPointer >= 0 && a[aPointer] >= i){
				aPointer--;
			}
			if (aPointer == -1){
				arr[i] = -1;
			} else {
				arr[i] = a[aPointer];
			}
		}
		return arr;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class bSolution{
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String args[]){
		int n = Integer.parseInt(next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(next());
		}
		int curr = 0;
		Arrays.sort(a);
		int max = 2*a[n-1];
		int[] arr = generateOrderArray(a);
		int currVal;
		int prev = 0;
		int check;
		for (int j = 0; j < n; j++){
			if (a[j] == prev){
				continue;
			}
			for(check = 2*a[j]; check < max; check += a[j]){
				if (arr[check] < check - a[j] && check != 2*a[j]){
					continue;
				}
				currVal = arr[check] - (check - a[j]);
				if (currVal > curr){
					curr = currVal;
				}
			}
			if (arr[max-1] > a[j]){
				if ((arr[max-1] - a[j])%a[j] > curr){
					curr = (arr[max-1] - a[j]) % a[j];
				}
			}
			prev = a[j];
		}
		System.out.println(curr);
	}

	private static StringTokenizer st;

	private static String next(){
		while (st == null || !st.hasMoreElements()){
			String str;
			try{
				str = br.readLine();
			} catch (IOException e){
				return null;
			}
			st = new StringTokenizer(str);
		}
		return st.nextToken();
	}

	private static int[] generateOrderArray(int[] a){
		int max = 2*a[a.length-1];
		int[] arr = new int[max];
		int aPointer = a.length-1;
		for (int i = max-1; i >= 0; i--){
			while(aPointer >= 0 && a[aPointer] >= i){
				aPointer--;
			}
			if (aPointer == -1){
				arr[i] = -1;
			} else {
				arr[i] = a[aPointer];
			}
		}
		return arr;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class bSolution{
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String args[]){
		int n = Integer.parseInt(next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(next());
		}
		int curr = 0;
		Arrays.sort(a);
		int max = 2*a[n-1];
		int[] arr = generateOrderArray(a);
		int currVal;
		int prev = 0;
		int check;
		for (int j = 0; j < n; j++){
			if (a[j] == prev){
				continue;
			}
			for(check = 2*a[j]; check < max; check += a[j]){
				if (arr[check] < check - a[j] && check != 2*a[j]){
					continue;
				}
				currVal = arr[check] - (check - a[j]);
				if (currVal > curr){
					curr = currVal;
				}
			}
			if (arr[check] < check - a[j] && check != 2*a[j]){
				continue;
			}
			currVal = arr[check] - (check - a[j]);
			if (currVal > curr){
				curr = currVal;
			}
			prev = a[j];
		}
		System.out.println(curr);
	}

	private static StringTokenizer st;

	private static String next(){
		while (st == null || !st.hasMoreElements()){
			String str;
			try{
				str = br.readLine();
			} catch (IOException e){
				return null;
			}
			st = new StringTokenizer(str);
		}
		return st.nextToken();
	}

	private static int[] generateOrderArray(int[] a){
		int max = 2*a[a.length-1];
		int[] arr = new int[max];
		int aPointer = a.length-1;
		for (int i = max-1; i >= 0; i--){
			while(aPointer >= 0 && a[aPointer] >= i){
				aPointer--;
			}
			if (aPointer == -1){
				arr[i] = -1;
			} else {
				arr[i] = a[aPointer];
			}
		}
		return arr;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class bSolution{
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String args[]){
		int n = Integer.parseInt(next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(next());
		}
		int curr = 0;
		Arrays.sort(a);
		int max = 2*a[n-1];
		int[] arr = generateOrderArray(a);
		int currVal;
		int prev = 0;
		int check;
		for (int j = 0; j < n; j++){
			if (a[j] == prev){
				continue;
			}
			for(check = 2*a[j]; check < max; check += a[j]){
				if (arr[check] < check - a[j] && check != 2*a[j]){
					continue;
				}
				currVal = arr[check] - (check - a[j]);
				if (currVal > curr){
					curr = currVal;
				}
			}
			if (arr[max-1] > a[j]){
				if (arr[max-1] - a[j] > curr){
					curr = (arr[max-1] - a[j]) % a[j];
				}
			}
			prev = a[j];
		}
		System.out.println(curr);
	}

	private static StringTokenizer st;

	private static String next(){
		while (st == null || !st.hasMoreElements()){
			String str;
			try{
				str = br.readLine();
			} catch (IOException e){
				return null;
			}
			st = new StringTokenizer(str);
		}
		return st.nextToken();
	}

	private static int[] generateOrderArray(int[] a){
		int max = 2*a[a.length-1];
		int[] arr = new int[max];
		int aPointer = a.length-1;
		for (int i = max-1; i >= 0; i--){
			while(aPointer >= 0 && a[aPointer] >= i){
				aPointer--;
			}
			if (aPointer == -1){
				arr[i] = -1;
			} else {
				arr[i] = a[aPointer];
			}
		}
		return arr;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class bSolution{
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String args[]){
		int n = Integer.parseInt(next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(next());
		}
		int curr = 0;
		Arrays.sort(a);
		int max = 2*a[n-1];
		int[] arr = generateOrderArray(a);
		int currVal;
		int prev = 0;
		for (int j = 0; j < n; j++){
			if (a[j] == prev){
				continue;
			}
			for(int check = 2*a[j]; check < max; check += a[j]){
				if (arr[check] < check - a[j] && check != 2*a[j]){
					continue;
				}
				currVal = arr[check] - (check - a[j]);
				if (currVal > curr){
					curr = currVal;
				}
			}
			if (arr[check] < check - a[j] && check != 2*a[j]){
				continue;
			}
			currVal = arr[check] - (check - a[j]);
			if (currVal > curr){
				curr = currVal;
			}
			prev = a[j];
		}
		System.out.println(curr);
	}

	private static StringTokenizer st;

	private static String next(){
		while (st == null || !st.hasMoreElements()){
			String str;
			try{
				str = br.readLine();
			} catch (IOException e){
				return null;
			}
			st = new StringTokenizer(str);
		}
		return st.nextToken();
	}

	private static int[] generateOrderArray(int[] a){
		int max = 2*a[a.length-1];
		int[] arr = new int[max];
		int aPointer = a.length-1;
		for (int i = max-1; i >= 0; i--){
			while(aPointer >= 0 && a[aPointer] >= i){
				aPointer--;
			}
			if (aPointer == -1){
				arr[i] = -1;
			} else {
				arr[i] = a[aPointer];
			}
		}
		return arr;
	}
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static int[] arr;
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            arr = new int[N];
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                arr[i] = parseInt(st.nextToken());
                set.add(arr[i]);
            }
            Arrays.sort(arr);
            int bruteForce = 0;
            int max=0;
            for (int i = N - 1; i < N; i++) {
                //bruteForce = Math.max(bruteForce, bruteForce(i));
                max = Math.max(max, f(arr[i]));
            }
            System.out.println(max);
        }
    }

    static int f(int T, int p) {
        return arr[T] % arr[p];
    }

    static int bruteForce(int T) {
        int max = 0;
        for (int i = 0; i < T; i++)
            max = Math.max(max, f(T, i));
        return max;
    }

    static int f(int T) {
        int max = 0;
        for (int i = 2; i <= Math.ceil(Math.sqrt(T)); i++) {
            for (int j = -1; j < 2; j++) {
                Integer a = set.floor(T/i+j);
                if(a!=null)max = Math.max(max, T%a);
                a = set.ceiling(T/i+j);
                if(a!=null)max = Math.max(max, T%a);
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class CF484B {
    static int[] arr;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            arr = new int[N];
            StringTokenizer st = new StringTokenizer(in.readLine());
            for (int i = 0; i < N; i++)
                arr[i] = parseInt(st.nextToken());
            Arrays.sort(arr);
            int max = 0;
            for (int i = 1; i < N; i++) {
                int t = ternarySerach(0, i / 2, i - 1, i);
                max = Math.max(max, arr[i] % arr[t]);
            }
            System.out.println(max);
        }
    }

    static int f(int T, int p) {
        return arr[T] % arr[p];
    }

    static int ternarySerach(int a, int b, int c, int T) {
        if (a != b) {
            if (a + 1 == b)
                if (f(T, a) > f(T, b))
                    return ternarySerach(a, a, c, T);
                else return ternarySerach(b, b, c, T);
            int p = (a + b) / 2 + (a + b) % 2;
            if (f(T, p) > f(T, b))
                return ternarySerach(p, (p + c) / 2 + (p + c) % 2, c, T);
        }
        if (b != c) {
            if (b + 1 == c)
                if (f(T, b) > f(T, c))
                    return b;
                else return c;
            int p = (b + c) / 2 + (b + c) % 2;
            if (f(T, p) > f(T, b))
                return ternarySerach(a, (a + c) / 2 + (a + c) % 2, p, T);
        }
        return b;
    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        long T=System.currentTimeMillis();
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                set.add(parseInt(st.nextToken()));
            }
            int max = 0;

            for (int a: set.descendingSet())
                if (a > max) {
                    max = Math.max(max, f(a));
                }

            System.out.println(max);
        }
    }

    static int f(int T) {
        int max = 0, N = Math.min((int)Math.ceil(Math.sqrt(T)), 10);
        for (int i = 2; i <= N; i++) {
            for (int j = -1; j < 2; j++) {
                Integer a = set.floor(T / i + j);
                if (a != null && a < T) max = Math.max(max, T % a);
                a = set.ceiling(T / i + j);
                if (a != null && a < T) max = Math.max(max, T % a);
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        long T = System.currentTimeMillis();
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                set.add(parseInt(st.nextToken()));
            }
            int max = 0;
            //int s=0;
            for (int a : set.descendingSet())
                if (a > max) {
                    max = Math.max(max, f(a, max));
                    //s+=Math.sqrt(a);
                }

            System.out.println(max);
        }
    }

    static int f(int T, int max) {
        int N = (int) Math.sqrt(T);
        for (int i = 2; i <= N; i++) {
            if (T / i > max) {
                Integer a = set.higher(T / i);
                if (a != null && a < T) max = Math.max(max, T % a);
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                set.add(parseInt(st.nextToken()));
            }
            int max = 0;
            //int s=0;
            for (int a : set.descendingSet())
                if (a > max) {
                    max = Math.max(max, f(a, max));
                    //s+=Math.sqrt(a);
                }

            System.out.println(max);
        }
    }

    static int f(int T, int max) {
        int N = (int) Math.ceil(Math.log(T) / Math.log(2));
        for (int i = 2; i <= N; i++) {
            if (T / i > max)
                for (int j = 0; j < 2; j++) {
                    Integer a = set.ceiling(T / i + j);
                    if (a != null && a < T) max = Math.max(max, T % a);
                }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class CF484B {

    static int[] arr;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        long T = System.currentTimeMillis();
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            StringTokenizer st = new StringTokenizer(in.readLine());
            int[] numbers = new int[N];
            int withOutRepeat = 0;
            int M = 1000001;
            arr = new int[M];
            boolean[] vis = new boolean[M];
            for (int i = 0; i < N; i++) {
                int n = parseInt(st.nextToken());
                if (!vis[n]) {
                    vis[n] = true;
                    numbers[withOutRepeat++] = n;
                }
            }
            Arrays.sort(numbers, 0, withOutRepeat);
            Arrays.fill(arr, -1);

            for (int i = withOutRepeat - 2; i >= 0; i--)
                for (int j = numbers[i]; j < numbers[i + 1]; j++)
                    arr[j] = numbers[i + 1];

            for (int j = 0; j < numbers[0]; j++)
                arr[j] = numbers[0];

            int max = 0;

            for (int i = withOutRepeat - 1; i >= 0; i--)
                max = Math.max(max, f(numbers[i], max));

            System.out.println(max);
            //System.out.println(System.currentTimeMillis() - T);
        }
    }

    static int f(int T, int max) {
        int N = (int) (Math.ceil(Math.log(T)/Math.log(2)));
        for (int i = 2; i <= N; i++) {
            for (int j = -1; j < 2; j++) {
                if (T / i + j >= 0) {
                    int a = arr[T / i + j];
                    if (a != -1) max = Math.max(max, T % a);
                }
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

public class CF484B {

    static int[] arr;

    public static void main(String args[]) throws Throwable {
        //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        BufferedReader in = new BufferedReader(new FileReader("in.in"));
        long T = System.currentTimeMillis();
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            StringTokenizer st = new StringTokenizer(in.readLine());
            ArrayList<Integer> list = new ArrayList<>(N);
            int M = 1000001;
            arr = new int[M];
            boolean[] vis = new boolean[M];
            for (int i = 0; i < N; i++) {
                int n = parseInt(st.nextToken());
                if(!vis[n]) {
                    vis[n]=true;
                    list.add(n);
                }
            }
            Collections.sort(list);
            Arrays.fill(arr, -1);

            for(int i=list.size()-2;i>=0;i--)
                for(int j = list.get(i); j < list.get(i+1);j++)
                    arr[j] = list.get(i + 1);

            for(int j=0;j<list.get(0);j++)
                arr[j] = list.get(0);

            int max = 0;

            for (int i=list.size()-1;i>=0;i--)
                if (list.get(i) > max) {
                    max = Math.max(max, f(list.get(i), max));
                    //s+=Math.sqrt(a);
                }

            System.out.println(max+" "+(System.currentTimeMillis()-T));
        }
    }

    static int f(int T, int max) {
        int N = (int) Math.sqrt(T);
        for (int i = 2; i <= N; i++) {
            int a = arr[T / i];
            if (a != -1) max = Math.max(max, T % a);
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

public class CF484B {

    static int[] arr;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        long T = System.currentTimeMillis();
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            StringTokenizer st = new StringTokenizer(in.readLine());
            ArrayList<Integer> list = new ArrayList<>(N);
            int M = 1000001;
            arr = new int[M];
            boolean[] vis = new boolean[M];
            for (int i = 0; i < N; i++) {
                int n = parseInt(st.nextToken());
                if(!vis[n]) {
                    vis[n]=true;
                    list.add(n);
                }
            }
            Collections.sort(list);
            Arrays.fill(arr, -1);

            for(int i=list.size()-2;i>=0;i--)
                for(int j = list.get(i); j < list.get(i+1);j++)
                    arr[j] = list.get(i + 1);

            for(int j=0;j<list.get(0);j++)
                arr[j] = list.get(0);

            int max = 0;

            for (int i=list.size()-1;i>=0;i--)
                if (list.get(i) > max) {
                    max = Math.max(max, f(list.get(i), max));
                    //s+=Math.sqrt(a);
                }

            System.out.println(max);
        }
    }

    static int f(int T, int max) {
        int N = (int) Math.sqrt(T);
        for (int i = 2; i <= N; i++) {
            if(T/i>max) {
                Integer a = arr[T / i];
                if (a != -1) max = Math.max(max, T % a);
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class CF484B {
    static int[] arr;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            arr = new int[N];
            StringTokenizer st = new StringTokenizer(in.readLine());
            for (int i = 0; i < N; i++)
                arr[i] = parseInt(st.nextToken());
            Arrays.sort(arr);
            int max = 0;
            for (int i = N - 1; i < N; i++) {
                int t = ternarySearch(0, i - 1, i);
                max = Math.max(max, arr[i] % arr[t]);
            }
            System.out.println(max);
        }
    }

    static int f(int T, int p) {
        return arr[T] % arr[p];
    }

    static int ternarySearch(int left, int right, int T) {
        if (left == right)
            return left;
        int leftThird = (2 * left + right) / 3;
        int rightThird = (left + 2 * right) / 3;
        if (f(leftThird, T) > f(rightThird, T))
            return ternarySearch(leftThird, right, T);
        else
            return ternarySearch(left, rightThird, T);
    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static int[] arr;
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            arr = new int[N];
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                arr[i] = parseInt(st.nextToken());
                set.add(arr[i]);
            }
            Arrays.sort(arr);
            //int bruteForce = 0;
            int max=0;
            for (int i = N - 1; i < N; i++) {
                //bruteForce = Math.max(bruteForce, bruteForce(i));
                max = Math.max(max, f(arr[i]));
            }
            //if(bruteForce!=max)
            System.out.println(max);
        }
    }

    static int f(int T, int p) {
        return arr[T] % arr[p];
    }

    static int bruteForce(int T) {
        int max = 0;
        for (int i = 0; i < T; i++)
            max = Math.max(max, f(T, i));
        return max;
    }

    static int f(int T) {
        int max = 0;
        for (int i = 1; i <= Math.ceil(Math.sqrt(T))+1; i++) {
            for (int j = -5; j < 5; j++) {
                Integer a = set.floor(T/i+j);
                if(a!=null)max = Math.max(max, T%a);
                a = set.ceiling(T/i+j);
                if(a!=null)max = Math.max(max, T%a);
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static int[] arr;
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            arr = new int[N];
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                arr[i] = parseInt(st.nextToken());
                set.add(arr[i]);
            }
            Arrays.sort(arr);
            //int bruteForce = 0;
            int max=0;
            for (int i = N - 1; i < N; i++) {
                //bruteForce = Math.max(bruteForce, bruteForce(i));
                max = Math.max(max, f(arr[i]));
            }
            //if(bruteForce!=max)
            System.out.println(max);
        }
    }

    static int f(int T, int p) {
        return arr[T] % arr[p];
    }

    static int bruteForce(int T) {
        int max = 0;
        for (int i = 0; i < T; i++)
            max = Math.max(max, f(T, i));
        return max;
    }

    static int f(int T) {
        int max = 0;
        for (int i = 1; i <= Math.ceil(Math.sqrt(T)); i++) {
            for (int j = -1; j < 2; j++) {
                Integer a = set.floor(T/i+j);
                if(a!=null)max = Math.max(max, T%a);
                a = set.ceiling(T/i+j);
                if(a!=null)max = Math.max(max, T%a);
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static int[] arr;
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            arr = new int[N];
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                arr[i] = parseInt(st.nextToken());
                set.add(arr[i]);
            }
            Arrays.sort(arr);
            //int bruteForce = 0;
            int max=0;
            for (int i = N - 1; i < N; i++) {
                //bruteForce = Math.max(bruteForce, bruteForce(i));
                max = Math.max(max, f(arr[i]));
            }
            //if(bruteForce!=max)
            System.out.println(max);
        }
    }

    static int f(int T, int p) {
        return arr[T] % arr[p];
    }

    static int bruteForce(int T) {
        int max = 0;
        for (int i = 0; i < T; i++)
            max = Math.max(max, f(T, i));
        return max;
    }

    static int f(int T) {
        int max = 0;
        for (int i = 1; i <= Math.ceil(Math.sqrt(T)); i++) {
            for (int j = -1; j < 2; j++) {
                Integer a = set.floor(T/i+j);
                if(a!=null)max = Math.max(max, T%a);
                a = set.ceiling(T/i+j);
                if(a!=null)max = Math.max(max, T%a);
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static int[] arr;
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            arr = new int[N];
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                arr[i] = parseInt(st.nextToken());
                set.add(arr[i]);
            }
            Arrays.sort(arr);
            //int bruteForce = 0;
            int max = 0;
            for (int i = N - 1; i >= 0; i--) {
                //bruteForce = Math.max(bruteForce, bruteForce(i));
                if (arr[i] > max)
                    max = Math.max(max, f(arr[i]));
            }
            //if(bruteForce!=max)
            System.out.println(max);
        }
    }

    static int f(int T, int p) {
        return arr[T] % arr[p];
    }

    static int bruteForce(int T) {
        int max = 0;
        for (int i = 0; i < T; i++)
            max = Math.max(max, f(T, i));
        return max;
    }

    static int f(int T) {
        int max = 0;
        for (int i = 2; i <= Math.ceil(Math.sqrt(T)); i++) {
            for (int j = -1; j < 2; j++) {
                Integer a = set.floor(T / i + j);
                if (a != null && a < T) max = Math.max(max, T % a);
                a = set.ceiling(T / i + j);
                if (a != null && a < T) max = Math.max(max, T % a);
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class CF484B {

    static int[] arr;
    static int[] arr1;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        long T = System.currentTimeMillis();
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            StringTokenizer st = new StringTokenizer(in.readLine());
            int[] numbers = new int[N];
            int withOutRepeat = 0;
            int M = 1000001;
            arr = new int[M];
            arr1 = new int[M];
            boolean[] vis = new boolean[M];
            for (int i = 0; i < N; i++) {
                int n = parseInt(st.nextToken());
                if (!vis[n]) {
                    vis[n] = true;
                    numbers[withOutRepeat++] = n;
                }
            }
            Arrays.sort(numbers, 0, withOutRepeat);
            Arrays.fill(arr, -1);
            Arrays.fill(arr1, -1);

            for (int i = withOutRepeat - 2; i >= 0; i--)
                for (int j = numbers[i]; j <= numbers[i + 1]; j++)
                    arr[j] = numbers[i + 1];

            for (int i = 1; i < withOutRepeat; i++)
                for (int j = numbers[i - 1]; j <= numbers[i]; j++)
                    arr1[j] = numbers[i - 1];

            for (int j = numbers[withOutRepeat - 1]; j < M; j++)
                arr1[j] = numbers[withOutRepeat - 1];

            for (int j = 0; j <= numbers[0]; j++)
                arr[j] = numbers[0];

            int max = 0;

            for (int i = withOutRepeat - 1; i >= 0; i--)
                if (numbers[i] > max) {
                    max = Math.max(max, f(numbers[i], max));
                } else break;

            System.out.println(max);
            //System.out.println(System.currentTimeMillis() - T);
        }
    }

    static int f(int T, int max) {
        int N = (int) Math.sqrt(T);
        for (int i = 2; i <= N + 1; i++) {
            if (T / i + 1 < max) break;
            for (int j = -1; j < 2; j++) {
                if (T / i + j >= 0) {
                    int a = arr[T / i + j];
                    if (a != -1) max = Math.max(max, T % a);
                    a = arr1[T / i + j];
                    if (a != -1) max = Math.max(max, T % a);
                }
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static int[] arr;
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            arr = new int[N];
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                arr[i] = parseInt(st.nextToken());
                set.add(arr[i]);
            }
            Arrays.sort(arr);
            //int bruteForce = 0;
            int max=0;
            for (int i = N - 1; i < N; i++) {
                //bruteForce = Math.max(bruteForce, bruteForce(i));
                max = Math.max(max, f(arr[i]));
            }
            //if(bruteForce!=max)
            System.out.println(max);
        }
    }

    static int f(int T, int p) {
        return arr[T] % arr[p];
    }

    static int bruteForce(int T) {
        int max = 0;
        for (int i = 0; i < T; i++)
            max = Math.max(max, f(T, i));
        return max;
    }

    static int f(int T) {
        int max = 0;
        for (int i = 1; i <= 10*Math.ceil(Math.sqrt(T))+1; i++) {
            for (int j = -1; j < 2; j++) {
                Integer a = set.floor(T/i+j);
                if(a!=null)max = Math.max(max, T%a);
                a = set.ceiling(T/i+j);
                if(a!=null)max = Math.max(max, T%a);
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                set.add(parseInt(st.nextToken()));
            }
            int max = 0;
            //int s=0;
            for (int a : set.descendingSet())
                if (a > max) {
                    max = Math.max(max, f(a, max));
                    //s+=Math.sqrt(a);
                }

            System.out.println(max);
        }
    }

    static int f(int T, int max) {
        int N = (int) Math.ceil(Math.sqrt(T));
        for (int i = 2; i <= N; i++) {
                for (int j = 0; j < 2; j++) {
                    if (T / i + j> max) {
                        Integer a = set.ceiling(T / i + j);
                        if (a != null && a < T) max = Math.max(max, T % a);
                    }
                }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class CF484B {

    static int[] arr;
    static int[] arr1;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        long T = System.currentTimeMillis();
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            StringTokenizer st = new StringTokenizer(in.readLine());
            int[] numbers = new int[N];
            int withOutRepeat = 0;
            int M = 1000001;
            arr = new int[M];
            arr1 = new int[M];
            boolean[] vis = new boolean[M];
            for (int i = 0; i < N; i++) {
                int n = parseInt(st.nextToken());
                if (!vis[n]) {
                    vis[n] = true;
                    numbers[withOutRepeat++] = n;
                }
            }
            Arrays.sort(numbers, 0, withOutRepeat);
            Arrays.fill(arr, -1);
            Arrays.fill(arr1, -1);

            for (int i = withOutRepeat - 2; i >= 0; i--)
                for (int j = numbers[i]; j <= numbers[i + 1]; j++)
                    arr[j] = numbers[i + 1];

            for (int i = 1; i < withOutRepeat; i++)
                for (int j = numbers[i - 1]; j <= numbers[i]; j++)
                    arr1[j] = numbers[i - 1];

            for (int j = numbers[withOutRepeat - 1]; j < M; j++)
                arr1[j] = numbers[withOutRepeat - 1];

            for (int j = 0; j <= numbers[0]; j++)
                arr[j] = numbers[0];

            int max = 0;

            for (int i = withOutRepeat - 1; i >= 0; i--)
                if (numbers[i] > max) {
                    max = Math.max(max, f(numbers[i], max));
                } else break;

            System.out.println(max);
            //System.out.println(System.currentTimeMillis() - T);
        }
    }

    static int f(int T, int max) {
        int N = (int) Math.sqrt(T);
        for (int i = 2; i <= N; i++) {
            if (T / i + 1 < max) break;
            for (int j = -1; j < 2; j++) {
                if (T / i + j >= 0) {
                    int a = arr[T / i + j];
                    if (a != -1) max = Math.max(max, T % a);
                    a = arr1[T / i + j];
                    if (a != -1) max = Math.max(max, T % a);
                }
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                set.add(parseInt(st.nextToken()));
            }
            int max = 0;
            //int s=0;
            for (int a : set.descendingSet())
                if (a > max) {
                    max = Math.max(max, f(a, max));
                    //s+=Math.sqrt(a);
                }

            System.out.println(max);
        }
    }

    static int f(int T, int max) {
        int N = (int) Math.ceil(Math.log(T) / Math.log(2));
        for (int i = 2; i <= N; i++) {
                for (int j = 0; j < 2; j++) {
                    //if (T / i > max) {
                        Integer a = set.ceiling(T / i + j);
                        if (a != null && a < T) max = Math.max(max, T % a);
                    //}
                }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

public class CF484B {

    static int[] arr;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        long T = System.currentTimeMillis();
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            StringTokenizer st = new StringTokenizer(in.readLine());
            int[] numbers = new int[N];
            int withOutRepeat = 0;
            int M = 1000001;
            arr = new int[M];
            boolean[] vis = new boolean[M];
            for (int i = 0; i < N; i++) {
                int n = parseInt(st.nextToken());
                if(!vis[n]) {
                    vis[n]=true;
                    numbers[withOutRepeat++]=n;
                }
            }
            Arrays.sort(numbers, 0, withOutRepeat);
            Arrays.fill(arr, -1);

            for(int i=withOutRepeat-2;i>=0;i--)
                for(int j = numbers[i]; j < numbers[i+1];j++)
                    arr[j] = numbers[i+1];

            for(int j=0;j<numbers[0];j++)
                arr[j] = numbers[0];

            int max = 0;

            for (int i=withOutRepeat-1;i>=0;i--)
                max = Math.max(max, f(numbers[i], max));

            System.out.println(max);
        }
    }

    static int f(int T, int max) {
        int N = (int) (Math.ceil(Math.log(T)/Math.log(2)));
        for (int i = 2; i <= N; i++) {
            int a = arr[T / i];
            if (a != -1) max = Math.max(max, T % a);
        }
        return max;

    }
}


package practice.codeforces;
/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static int[] arr;
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            arr = new int[N];
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                arr[i] = parseInt(st.nextToken());
                set.add(arr[i]);
            }
            Arrays.sort(arr);
            //int bruteForce = 0;
            int max=0;
            for (int i = N - 1; i < N; i++) {
                //bruteForce = Math.max(bruteForce, bruteForce(i));
                max = Math.max(max, f(arr[i]));
            }
            //if(bruteForce!=max)
            System.out.println(max);
        }
    }

    static int f(int T, int p) {
        return arr[T] % arr[p];
    }

    static int bruteForce(int T) {
        int max = 0;
        for (int i = 0; i < T; i++)
            max = Math.max(max, f(T, i));
        return max;
    }

    static int f(int T) {
        int max = 0;
        for (int i = 1; i <= Math.ceil(Math.sqrt(T)); i++) {
            for (int j = -1; j < 2; j++) {
                Integer a = set.floor(T/i+j);
                if(a!=null)max = Math.max(max, T%a);
                a = set.ceiling(T/i+j);
                if(a!=null)max = Math.max(max, T%a);
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                set.add(parseInt(st.nextToken()));
            }
            int max = 0;
            //int s=0;
            for (int a : set.descendingSet())
                if (a > max) {
                    max = Math.max(max, f(a, max));
                    //s+=Math.sqrt(a);
                }

            System.out.println(max);
        }
    }

    static int f(int T, int max) {
        int N = (int) Math.ceil(Math.log(T) / Math.log(2));
        for (int i = 2; i <= N; i++) {
                for (int j = 0; j < 2; j++) {
                    if (T / i > max) {
                        Integer a = set.ceiling(T / i + j);
                        if (a != null && a < T) max = Math.max(max, T % a);
                    }
                }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        long T=System.currentTimeMillis();
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                set.add(parseInt(st.nextToken()));
            }
            int max = 0;
            for (int a: set.descendingSet())
                if (a > max) {
                    max = Math.max(max, f(a));
                }

            System.out.println(max);
        }
    }

    static int f(int T) {
        int max = 0, N = Math.min((int)Math.ceil(Math.sqrt(T)), 2);
        for (int i = 2; i <= N; i++) {
            for (int j = -1; j < 2; j++) {
                Integer a = set.floor(T / i + j);
                if (a != null && a < T) max = Math.max(max, T % a);
                a = set.ceiling(T / i + j);
                if (a != null && a < T) max = Math.max(max, T % a);
            }
        }
        return max;

    }
}


/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class CF484B {
    static int[] arr;
    static TreeSet<Integer> set;

    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("in.in"));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = parseInt(ln);
            arr = new int[N];
            StringTokenizer st = new StringTokenizer(in.readLine());
            set = new TreeSet<>();
            for (int i = 0; i < N; i++) {
                arr[i] = parseInt(st.nextToken());
                set.add(arr[i]);
            }
            Arrays.sort(arr);
            //int bruteForce = 0;
            int max=0;
            for (int i = 0; i < N; i++) {
                //bruteForce = Math.max(bruteForce, bruteForce(i));
                max = Math.max(max, f(arr[i]));
            }
            //if(bruteForce!=max)
            System.out.println(max);
        }
    }

    static int f(int T, int p) {
        return arr[T] % arr[p];
    }

    static int bruteForce(int T) {
        int max = 0;
        for (int i = 0; i < T; i++)
            max = Math.max(max, f(T, i));
        return max;
    }

    static int f(int T) {
        int max = 0;
        for (int i = 1; i <= Math.ceil(Math.sqrt(T))+1; i++) {
            for (int j = -1; j < 2; j++) {
                Integer a = set.floor(T/i+j);
                if(a!=null&&a<T)max = Math.max(max, T%a);
                a = set.ceiling(T/i+j);
                if(a!=null&&a<T)max = Math.max(max, T%a);
            }
        }
        return max;

    }
}