#include <bits/stdc++.h>
using namespace std;
namespace solver {
namespace SAM {
static const int maxnode = 11000 + 10;
static const int maxn = 26;
int p, q, np, nq;
int cnt, ST_T, len;
int deg[maxnode], right[maxnode], match[maxnode];
vector<int> G;
int trans[maxnode][maxn], l[maxnode], fa[maxnode];
int newnode() {
  int x = ++cnt;
  memset(trans[x], 0, sizeof trans[x]);
  fa[x] = 0;
  l[x] = 0;
  return cnt;
}
void init() {
  cnt = 0;
  ST_T = newnode();
  memset(right, 0, sizeof right);
  memset(deg, 0, sizeof deg);
  G.clear();
}
void add(int c) {
  p = ST_T;
  np = ST_T = newnode();
  l[np] = l[p] + 1;
  while (!trans[p][c] && p) trans[p][c] = np, p = fa[p];
  if (!p)
    fa[np] = 1;
  else {
    q = trans[p][c];
    if (l[p] + 1 == l[q])
      fa[np] = q;
    else {
      nq = newnode();
      l[nq] = l[p] + 1;
      memcpy(trans[nq], trans[q], sizeof(trans[q]));
      fa[nq] = fa[q];
      fa[np] = fa[q] = nq;
      while (trans[p][c] == q) trans[p][c] = nq, p = fa[p];
    }
  }
}
void build(string str) {
  len = str.size();
  for (int i = 0; i < len; i++) {
    add(str[i] - 'a');
  }
  for (int i = 1; i <= cnt; i++)
    for (int j = 0; j < 26; j++)
      if (trans[i][j]) deg[trans[i][j]]++;
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    G.push_back(u);
    for (int i = 0; i < 26; i++)
      if (trans[u][i]) {
        --deg[trans[u][i]];
        if (deg[trans[u][i]] == 0) q.push(trans[u][i]);
      }
  }
  int p = 1;
  for (int i = 0; i < len; i++) {
    p = trans[p][str[i] - 'a'];
    right[p]++;
  }
  for (int i = G.size() - 1; i >= 0; i--) {
    int val = G[i];
    right[fa[val]] += right[val];
  }
}
};  // namespace SAM
string s1, s2;
using namespace SAM;
void solve() {
  init();
  cin >> s1 >> s2;
  build(s1);
  int p = 1;
  int res = 5500;
  for (int i = 0; i < s2.size(); i++) {
    if (trans[p][s2[i] - 'a']) {
      p = trans[p][s2[i] - 'a'];
    } else {
      while (p && !trans[p][s2[i] - 'a']) {
        p = fa[p];
      }
      if (!p) {
        p = 1;
      } else {
        p = trans[p][s2[i] - 'a'];
      }
    }
    match[p]++;
  }
  for (int i = G.size() - 1; i >= 0; i--) {
    int v = G[i];
    match[fa[v]] += match[v];
  }
  for (int i = 2; i <= cnt; i++) {
    if (match[i] == 1 && right[i] == 1) {
      res = min(res, l[fa[i]] + 1);
    }
  }
  if (res == 5500)
    puts("-1");
  else
    printf("%d\n", res);
}
};  // namespace solver
int main() { solver::solve(); }
