#include <bits/stdc++.h>
using namespace std;
const int maxn = 15555;
int z[maxn];
string s1, s2, t;
void zzz() {
  int ll = t.length();
  int l = -1, r = -1;
  for (int i = 1; i < ll; ++i) {
    z[i] = i > r ? 0 : min(z[i - l], r - i + 1);
    while (i + z[i] < ll && t[i + z[i]] == t[z[i]]) ++z[i];
    if (i + z[i] - 1 > r) r = i + z[i] - 1, l = i;
  }
}
int main() {
  cin >> s1 >> s2;
  int l1 = s1.length(), l2 = s2.length();
  int ans = 5555;
  for (int i = 0; i < l1; ++i) {
    t = s1.substr(i, l1 - i) + '#' + s1 + '@' + s2;
    zzz();
    z[l1 + 1] = 0;
    int ll = t.length();
    int max1 = 0, max2 = 0, idx = 0;
    for (int j = 0; j < ll; ++j) {
      if (z[j] > max1) {
        max2 = max1;
        max1 = z[j];
        idx = j;
      } else if (z[j] > max2)
        max2 = z[j];
    }
    if (max1 != max2 && idx > l1 * 2 - i + 1) {
      ans = min(ans, max2 + 1);
    }
  }
  if (ans == 5555)
    puts("-1");
  else
    printf("%d\n", ans);
  return 0;
}
