#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 10, mod = (int)1e9 + 7;
int n1, n2, last, sz;
char s[N], t[N];
struct state {
  int len, link, next[27], cnt[2];
};
vector<state> st;
vector<int> adj[2 * N];
void sa_init() {
  st.resize((n1 + n2 + 1) << 1);
  st[0].link = -1;
  sz = 1;
  last = 0;
}
void sa_extend(char ch, int bo) {
  int c = ch - 'a';
  int cur = sz++;
  st[cur].len = st[last].len + 1;
  int p = last;
  while (p != -1 && !st[p].next[c]) {
    st[p].next[c] = cur;
    p = st[p].link;
  }
  if (p == -1)
    st[cur].link = 0;
  else {
    int q = st[p].next[c];
    if (st[q].len == st[p].len + 1)
      st[cur].link = q;
    else {
      int clone = sz++;
      st[clone] = st[q];
      st[clone].cnt[0] = st[clone].cnt[1] = 0;
      st[clone].len = st[p].len + 1;
      while (p != -1 && st[p].next[c] == q) {
        st[p].next[c] = clone;
        p = st[p].link;
      }
      st[q].link = st[cur].link = clone;
    }
  }
  last = cur;
  if (bo < 2) st[cur].cnt[bo] = 1;
}
void dfs(int u) {
  for (int v : adj[u]) {
    dfs(v);
    st[u].cnt[0] += st[v].cnt[0];
    st[u].cnt[1] += st[v].cnt[1];
  }
}
int main() {
  scanf("%s%s", &s, &t);
  n1 = strlen(s), n2 = strlen(t);
  sa_init();
  for (int i = 0; i < n1; i++) sa_extend(s[i], 0);
  sa_extend('z' + 1, 3);
  for (int i = 0; i < n2; i++) sa_extend(t[i], 1);
  for (int i = 1; i < sz; i++) adj[st[i].link].push_back(i);
  dfs(0);
  int ans = 1e9;
  for (int i = 0; i < n1; i++) {
    int u = 0, l = i, len = 0;
    while (l < n1) {
      int c = s[l++] - 'a';
      if (!st[u].next[c]) break;
      u = st[u].next[c];
      len++;
      if ((st[u].cnt[0] == st[u].cnt[1]) && st[u].cnt[0] == 1)
        ans = min(ans, len);
    }
  }
  ans = (ans == 1e9 ? -1 : ans);
  printf("%d\n", ans);
  return 0;
}
