#include <bits/stdc++.h>
using namespace std;
vector<int> z_function(string s);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s, t;
  cin >> s >> t;
  int ans = INT_MAX;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    vector<int> v1 = z_function(s.substr(i, n - i) + '$' + t);
    vector<int> v2 = z_function(s.substr(i, n - i) + '$' + s);
    int mx = max(v1.size(), v2.size());
    v1.resize(mx, 0);
    v2.resize(mx, 0);
    for (int i = 1; i < mx; i++) {
      if (v1[i] == 1 && v2[i] == 1) {
        ans = min(ans, i);
        break;
      }
    }
  }
  cout << (ans == INT_MAX ? -1 : ans) << endl;
}
vector<int> z_function(string s) {
  int n = s.size();
  vector<int> z(n, 0);
  int l = 0, r = 0;
  for (int i = 1; i < n; i++) {
    if (i > r) {
      l = r = i;
      while (r < n && s[r] == s[r - l]) r++;
      r--;
      z[i] = r - l + 1;
    } else {
      int k = i - l;
      if (z[k] < r - i + 1)
        z[i] = z[k];
      else {
        l = i;
        while (r < n && s[r] == s[r - l]) r++;
        r--;
        z[i] = r - l + 1;
      }
    }
  }
  vector<int> diff(n + 1, 0);
  for (auto i : z) {
    diff[1]++;
    diff[i + 1]--;
  }
  vector<int> pref(n + 1);
  partial_sum(diff.begin(), diff.end(), pref.begin());
  return pref;
}
