#include <bits/stdc++.h>
using namespace std;
int n, t;
int p[100005], r[100005], h[100005];
string s = "";
void fix_index(int *b, int *e) {
  int pkm1, pk, np, i, d, m;
  pkm1 = p[*b + t];
  m = e - b;
  d = 0;
  np = b - r;
  for (i = 0; i < m; i++) {
    if (((pk = p[*b + t]) != pkm1) && !(np <= pkm1 && pk < np + m)) {
      pkm1 = pk;
      d = i;
    }
    p[*(b++)] = np + d;
  }
}
bool comp(int i, int j) { return p[i + t] < p[j + t]; }
void suffix() {
  int i, j, bc[256];
  t = 1;
  for (i = 0; i < 256; i++) bc[i] = 0;
  for (i = 0; i < n; i++) ++bc[int(s[i])];
  for (i = 1; i < 256; i++) bc[i] += bc[i - 1];
  for (i = 0; i < n; i++) r[--bc[int(s[i])]] = i;
  for (i = n - 1; i >= 0; i--) p[i] = bc[int(s[i])];
  for (t = 1; t < n; t *= 2) {
    for (i = 0, j = 1; i < n; i = j++) {
      while (j < n && p[r[j]] == p[r[i]]) ++j;
      if (j - i > 1) {
        sort(r + i, r + j, comp);
        fix_index(r + i, r + j);
      }
    }
  }
}
void lcp() {
  int tam = 0, i, j;
  for (i = 0; i < n; i++)
    if (p[i] > 0) {
      j = r[p[i] - 1];
      while (s[i + tam] == s[j + tam]) ++tam;
      h[p[i] - 1] = tam;
      if (tam > 0) --tam;
    }
  h[n - 1] = 0;
}
string s1, s2;
bool vale(int id, int val) {
  if (id < 0) return 1;
  if (id >= n - 1) return 1;
  return h[id] < val;
}
int get(int id) {
  if (id < 0) return 0;
  if (id >= n - 1) return 0;
  return h[id];
}
int main() {
  cin >> s1 >> s2;
  int sz1 = s1.size(), sz2 = s2.size();
  for (int i = 0; i < sz1; ++i) {
    s += s1[i];
  }
  s += "#";
  for (int i = 0; i < sz2; ++i) {
    s += s2[i];
  }
  s += "$";
  n = s.size();
  suffix(), lcp();
  int mini = 10000000;
  for (int i = 0; i < n - 1; ++i) {
    if ((r[i] < sz1 && r[i + 1] > sz1) || (r[i] > sz1 && r[i + 1] < sz1)) {
      int cur = h[i];
      if (cur == 0) continue;
      if (vale(i - 1, cur) && vale(i + 1, cur)) {
        mini = min(mini, max(get(i - 1), get(i + 1)) + 1);
      }
    }
  }
  if (mini == 10000000)
    puts("-1");
  else
    cout << mini << endl;
}
