#include <bits/stdc++.h>
using namespace std;
const int N = 300007;
const int IT = 500000;
struct xorshift {
  unsigned x, y, z, w;
  xorshift() : x(123456789), y(328932), z(7777777), w(898329832) {}
  unsigned dsljhfdskjfdshkjfds() {
    unsigned t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = w ^ (w >> 19) ^ t ^ (t >> 8);
  }
  unsigned dsljhfdskjfdshkjfds(unsigned a) { return dsljhfdskjfdshkjfds() % a; }
  int dsljhfdskjfdshkjfds(int a, int b) {
    return a + dsljhfdskjfdshkjfds(b - a + 1);
  }
} rng;
int n, a[N], g;
bool have[N];
int i1, i2, i3, i4, i5, i6;
int dsljhfdskjfdshkjfds(int a, int b) { return rng.dsljhfdskjfdshkjfds(a, b); }
int gcd(int a, int b) {
  int r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int gcd(int a, int b, int c) { return gcd(a, gcd(b, c)); }
int gcd(int a, int b, int c, int d) { return gcd(gcd(a, b), gcd(c, d)); }
int gcd(int a, int b, int c, int d, int e) {
  return gcd(gcd(a, b, c), gcd(d, e));
}
int gcd(int a, int b, int c, int d, int e, int f) {
  return gcd(gcd(a, b), gcd(c, d), gcd(e, f));
}
bool try2() {
  int i;
  for (i = 1; i + 1 <= n; i++) {
    if (gcd(a[i], a[i + 1]) == 1) return true;
  }
  if (n <= 1000) {
    for (i1 = 1; i1 <= n; i1++) {
      for (i2 = i1 + 1; i2 <= n; i2++) {
        if (gcd(a[i1], a[i2]) == 1) return true;
      }
    }
  } else {
    for (i = 1; i <= IT; i++) {
      i1 = dsljhfdskjfdshkjfds(1, n - 1);
      i2 = dsljhfdskjfdshkjfds(i1 + 1, n);
      if (gcd(a[i1], a[i2]) == 1) return true;
    }
  }
  return false;
}
bool try3() {
  int i;
  for (i = 1; i + 2 <= n; i++) {
    if (gcd(a[i], a[i + 1], a[i + 2]) == 1) return true;
  }
  if (n <= 70) {
    for (i1 = 1; i1 <= n; i1++) {
      for (i2 = i1 + 1; i2 <= n; i2++) {
        for (i3 = i2 + 1; i3 <= n; i3++) {
          if (gcd(a[i1], a[i2], a[i3]) == 1) return true;
        }
      }
    }
  } else {
    for (i = 1; i <= IT; i++) {
      i1 = dsljhfdskjfdshkjfds(1, n - 2);
      i2 = dsljhfdskjfdshkjfds(i1 + 1, n - 1);
      i3 = dsljhfdskjfdshkjfds(i2 + 1, n);
      if (gcd(a[i1], a[i2], a[i3]) == 1) return true;
    }
  }
  return false;
}
bool try4() {
  int i;
  for (i = 1; i + 3 <= n; i++) {
    if (gcd(a[i], a[i + 1], a[i + 2], a[i + 3]) == 1) return true;
  }
  if (n <= 30) {
    for (i1 = 1; i1 <= n; i1++) {
      for (i2 = i1 + 1; i2 <= n; i2++) {
        for (i3 = i2 + 1; i3 <= n; i3++) {
          for (i4 = i3 + 1; i4 <= n; i4++) {
            if (gcd(a[i1], a[i2], a[i3], a[i4]) == 1) return true;
          }
        }
      }
    }
  } else {
    for (i = 1; i <= IT; i++) {
      i1 = dsljhfdskjfdshkjfds(1, n - 3);
      i2 = dsljhfdskjfdshkjfds(i1 + 1, n - 2);
      i3 = dsljhfdskjfdshkjfds(i2 + 1, n - 1);
      i4 = dsljhfdskjfdshkjfds(i3 + 1, n);
      if (gcd(a[i1], a[i2], a[i3], a[i4]) == 1) return true;
    }
  }
  return false;
}
bool try5() {
  int i;
  for (i = 1; i + 4 <= n; i++) {
    if (gcd(a[i], a[i + 1], a[i + 2], a[i + 3], a[i + 4]) == 1) return true;
  }
  if (n <= 15) {
    for (i1 = 1; i1 <= n; i1++) {
      for (i2 = i1 + 1; i2 <= n; i2++) {
        for (i3 = i2 + 1; i3 <= n; i3++) {
          for (i4 = i3 + 1; i4 <= n; i4++) {
            for (i5 = i4 + 1; i5 <= n; i5++) {
              if (gcd(a[i1], a[i2], a[i3], a[i4], a[i5]) == 1) return true;
            }
          }
        }
      }
    }
  } else {
    for (i = 1; i <= IT; i++) {
      i1 = dsljhfdskjfdshkjfds(1, n - 4);
      i2 = dsljhfdskjfdshkjfds(i1 + 1, n - 3);
      i3 = dsljhfdskjfdshkjfds(i2 + 1, n - 2);
      i4 = dsljhfdskjfdshkjfds(i3 + 1, n - 1);
      i5 = dsljhfdskjfdshkjfds(i4 + 1, n);
      if (gcd(a[i1], a[i2], a[i3], a[i4], a[i5]) == 1) return true;
    }
  }
  return false;
}
bool try6() {
  int i;
  for (i = 1; i + 5 <= n; i++) {
    if (gcd(a[i], a[i + 1], a[i + 2], a[i + 3], a[i + 4], a[i + 5]) == 1)
      return true;
  }
  if (n <= 10) {
    for (i1 = 1; i1 <= n; i1++) {
      for (i2 = i1 + 1; i2 <= n; i2++) {
        for (i3 = i2 + 1; i3 <= n; i3++) {
          for (i4 = i3 + 1; i4 <= n; i4++) {
            for (i5 = i4 + 1; i5 <= n; i5++) {
              for (i6 = i5 + 1; i6 <= n; i6++) {
                if (gcd(a[i1], a[i2], a[i3], a[i4], a[i5], a[i6]) == 1)
                  return true;
              }
            }
          }
        }
      }
    }
  } else {
    for (i = 1; i <= IT; i++) {
      i1 = dsljhfdskjfdshkjfds(1, n - 5);
      i2 = dsljhfdskjfdshkjfds(i1 + 1, n - 4);
      i3 = dsljhfdskjfdshkjfds(i2 + 1, n - 3);
      i4 = dsljhfdskjfdshkjfds(i3 + 1, n - 2);
      i5 = dsljhfdskjfdshkjfds(i4 + 1, n - 1);
      i6 = dsljhfdskjfdshkjfds(i5 + 1, n);
      if (gcd(a[i1], a[i2], a[i3], a[i4], a[i5], a[i6]) == 1) return true;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    have[a[i]] = true;
  }
  if (have[1]) {
    printf("1\n");
    return 0;
  }
  for (i = 1; i <= 300000; i++)
    if (have[i]) {
      for (j = i + i; j <= 300000; j += i) {
        have[j] = false;
      }
    }
  n = 0;
  for (i = 1; i <= 300000; i++)
    if (have[i]) {
      a[++n] = i;
    }
  for (i = 1; i <= n; i++) {
    g = gcd(g, a[i]);
  }
  if (g > 1) {
    printf("-1\n");
    return 0;
  }
  if (try2()) {
    printf("2\n");
  } else if (try3()) {
    printf("3\n");
  } else if (try4()) {
    printf("4\n");
  } else if (try5()) {
    printf("5\n");
  } else if (try6()) {
    printf("6\n");
  } else {
    printf("7\n");
  }
  return 0;
}
