#include <bits/stdc++.h>
using namespace std;
char c[10010];
int nextt[10010];
int num[5010];
int p1[5010], p2[5010];
int main() {
  char c1[5010], c2[5010];
  scanf("%s", c1);
  int l = strlen(c1);
  scanf("%s", c2);
  int lsum = l + strlen(c2);
  for (int i = 1; i <= lsum; i++)
    if (i <= l)
      c[i] = c1[i - 1];
    else
      c[i] = c2[i - l - 1];
  memset(nextt, 0, sizeof(nextt));
  memset(num, 0, sizeof(num));
  int ans = 0x3fffffff, p;
  for (int k = 1; k <= l; k++) {
    p = k - 1;
    nextt[k] = p;
    memset(p1, 0, sizeof(p1));
    memset(p2, 0, sizeof(p2));
    for (int i = k + 1; i <= l; i++) {
      while (p > k - 1 && c[p + 1] != c[i]) p = nextt[p];
      if (c[p + 1] == c[i]) p++;
      nextt[i] = p;
      if (p - k + 1 > num[i]) num[i] = p - k + 1;
      ++p1[p - k + 1];
    }
    p = k - 1;
    for (int i = l + 1; i <= lsum; i++) {
      while (p > k - 1 && (p + 1 > l || c[p + 1] != c[i])) p = nextt[p];
      if (c[p + 1] == c[i]) p++;
      nextt[i] = p;
      ++p2[p - k + 1];
    }
    for (int i = 1; i <= l; i++)
      if (p1[i] == 0 && p2[i] == 1) {
        if (num[k + i - 1] >= i) continue;
        if (i < ans) ans = i;
        break;
      }
  }
  printf("%d\n", ans < 0x3fffffff ? ans : -1);
  return 0;
}
