#include <bits/stdc++.h>
using namespace std;
int Count[100005], output[100005];
struct suffixArray {
  int pos[100005], index[18][100005], lcp[100005], len, mlgn;
  suffixArray() {}
  suffixArray(const char *S) { create(S); }
  void CountSort(int add) {
    int to = max(len, 27);
    memset(Count, 0, sizeof(Count));
    for (int i = 0; i < len; i++)
      ++Count[(((pos[i] + add) < len) ? index[mlgn][pos[i] + add] : -1) + 1];
    for (int i = 1; i <= to; i++) Count[i] += Count[i - 1];
    for (int i = len - 1; i >= 0; i--)
      output[--Count[(((pos[i] + add) < len) ? index[mlgn][pos[i] + add] : -1) +
                     1]] = pos[i];
    for (int i = 0; i < len; i++) pos[i] = output[i];
  }
  int Lcp(int x, int y) {
    int ret = 0;
    for (int i = mlgn; i >= 0 && x < len && y < len; i--)
      if (index[i][x] == index[i][y])
        x += (1 << i), y += (1 << i), ret += (1 << i);
    return ret;
  }
  void create(const char *S) {
    len = strlen(S), mlgn = 0;
    for (int i = 0; i < len; i++) index[0][i] = S[i] - 'a';
    for (int done = 1; done < len; done <<= 1) {
      for (int i = 0; i < len; i++) pos[i] = i;
      CountSort(done);
      CountSort(0);
      for (int i = 0; i < len; i++) {
        int sc1 = (i > 0) ? (((pos[i - 1] + done) < len)
                                 ? index[mlgn][pos[i - 1] + done]
                                 : -1)
                          : -1;
        int sc2 = (((pos[i] + done) < len) ? index[mlgn][pos[i] + done] : -1);
        index[mlgn + 1][pos[i]] =
            (i > 0 && index[mlgn][pos[i]] == index[mlgn][pos[i - 1]] &&
             sc1 == sc2)
                ? index[mlgn + 1][pos[i - 1]]
                : i;
      }
      mlgn++;
    }
    lcp[0] = 0;
    for (int i = 1; i < len; i++) lcp[i] = Lcp(pos[i], pos[i - 1]);
  }
};
suffixArray node;
char str[100005], b[100005];
int main() {
  int i, j, t, l, r, m;
  scanf("%s", str);
  m = strlen(str);
  str[m] = ('z' + 1);
  scanf("%s", b);
  strcat(str, b);
  int ans = 0, n = strlen(str);
  node.create(str);
  ans = 1e7;
  for (i = 1; i < n; i++) {
    if (node.pos[i] < m && node.pos[i - 1] < m) continue;
    if (node.pos[i] >= m && node.pos[i - 1] >= m) continue;
    int z = node.lcp[i];
    if (node.pos[i] < m)
      z = min(z, m - node.pos[i]);
    else
      z = min(z, n - node.pos[i]);
    if (node.pos[i - 1] < m)
      z = min(z, m - node.pos[i - 1]);
    else {
      z = min(z, n - node.pos[i - 1]);
    }
    int x = 0, y = 0;
    if (i - 1 > 0) {
      x = node.lcp[i - 1];
      if (node.pos[i - 1] < m)
        x = min(x, m - node.pos[i - 1]);
      else
        x = min(x, n - node.pos[i - 1]);
      if (node.pos[i - 2] < m)
        x = min(x, m - node.pos[i - 2]);
      else
        x = min(x, n - node.pos[i - 2]);
    }
    if (i + 1 < n) {
      y = node.lcp[i + 1];
      if (node.pos[i] < m)
        y = min(y, m - node.pos[i]);
      else
        y = min(y, n - node.pos[i]);
      if (node.pos[i + 1] < m)
        y = min(y, m - node.pos[i + 1]);
      else
        y = min(y, n - node.pos[i + 1]);
    }
    if (max(x, y) < z) {
      ans = min(ans, max(x, y) + 1);
    }
  }
  if (ans == 1e7)
    printf("-1\n");
  else
    printf("%d\n", ans);
}
