#include <bits/stdc++.h>
using namespace std;
const int N = 20202;
int t, n, k, sa[N], lcp[N], r[N], tmp[N], c[N], L[N], R[N];
string s;
bool suffCmp(int u, int v) {
  if (r[u] != r[v]) return r[u] < r[v];
  if (u + k < n && v + k < n) return r[u + k] < r[v + k];
  return (u > v);
}
void CountingSort(int k) {
  memset(c, 0, sizeof(c));
  for (int i = 0; i < n; i++) {
    int u = (i + k < n ? r[i + k] + 1 : 0);
    c[u]++;
  }
  for (int i = 1; i <= max(n, 256); i++) c[i] += c[i - 1];
  for (int i = n - 1; i >= 0; i--) {
    int u = (sa[i] + k < n ? r[sa[i] + k] + 1 : 0);
    tmp[--c[u]] = sa[i];
  }
  for (int i = 0; i < n; i++) sa[i] = tmp[i];
}
void makeSA() {
  for (int i = 0; i < n; i++) sa[i] = i, r[i] = s[i];
  for (k = 1; k < n; k <<= 1) {
    CountingSort(k);
    CountingSort(0);
    tmp[sa[0]] = 0;
    for (int i = 1; i < n; i++)
      tmp[sa[i]] = tmp[sa[i - 1]] + suffCmp(sa[i - 1], sa[i]);
    for (int i = 0; i < n; i++) r[i] = tmp[i];
    if (tmp[sa[n - 1]] == n - 1) break;
  }
}
void makeLCP() {
  for (int i = 0, k = 0; i < n; i++, k -= (k > 0))
    if (r[i] != n - 1) {
      int j = sa[r[i] + 1];
      while (i + k < n && j + k < n && s[i + k] == s[j + k]) k++;
      lcp[r[i]] = k;
    }
}
void makeLR() {
  for (int i = 0; i < n; i++) {
    L[i] = i;
    int j = i - 1;
    while (j >= 0 && lcp[i] <= lcp[j]) L[i] = L[j], j = L[j] - 1;
  }
  for (int i = n - 1; i >= 0; i--) {
    R[i] = i;
    int j = i + 1;
    while (j < n && lcp[i] <= lcp[j]) R[i] = R[j], j = R[j] + 1;
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string r;
  cin >> s >> r;
  int len = s.size();
  s = s + "$" + r;
  n = s.size();
  makeSA();
  makeLCP();
  makeLR();
  int ans = 1e9;
  for (int i = 0; i < n; i++)
    if (lcp[i] > 0 && R[i] - L[i] == 0)
      if ((sa[i] <= len && sa[i + 1] >= len) ||
          (sa[i] >= len && sa[i + 1] <= len)) {
        int trai = (i == 0 ? lcp[i] : lcp[i - 1] + 1);
        int phai = (i == n - 1 ? lcp[i] : lcp[i + 1] + 1);
        int vt = max(trai, phai);
        int kk = min(lcp[i], vt);
        if (kk < ans) {
          ans = kk;
        }
      }
  if (ans < 1e9)
    cout << ans;
  else
    cout << -1;
  return 0;
}
