#include <bits/stdc++.h>
using namespace std;
string text;
short minDepthWithUniqueSubstr;
class SuffixNode {
 public:
  short pos;
  short len;
  map<char, SuffixNode *> children;
};
struct freqTuplet {
  short t1;
  short t2;
};
void addSuffix(SuffixNode *n, short pos, short len) {
  short i;
  for (i = 0; i < n->len && text[pos + i] == text[n->pos + i]; i++)
    ;
  if (i == n->len) {
    if (n->children.count(text[pos + i])) {
      addSuffix(n->children[text[pos + i]], pos + i, len - i);
    } else {
      SuffixNode *sn = new SuffixNode();
      sn->pos = pos + i;
      sn->len = len - i;
      n->children[text[pos + i]] = sn;
    }
  } else {
    SuffixNode *splitNode = new SuffixNode();
    splitNode->pos = n->pos + i;
    splitNode->len = n->len - i;
    splitNode->children = n->children;
    n->len = i;
    n->children.clear();
    n->children[text[splitNode->pos]] = splitNode;
    SuffixNode *sn = new SuffixNode();
    sn->pos = pos + i;
    sn->len = len - i;
    n->children[text[pos + i]] = sn;
  }
}
void printAllSuffixes(SuffixNode *n) {
  for (std::map<char, SuffixNode *>::iterator it = n->children.begin();
       it != n->children.end(); ++it) {
    std::cout << it->first << " => " << it->second
              << ": (pos=" << it->second->pos << ", len=" << it->second->len
              << ", text=" << text.substr(it->second->pos, it->second->len)
              << ")" << endl;
    printAllSuffixes(it->second);
  }
}
freqTuplet getMinUniqueSubstr(SuffixNode *n, short strLen) {
  freqTuplet cf;
  cf.t1 = 0;
  cf.t2 = 0;
  if (n->children.empty()) {
    if (text[n->pos + n->len - 1] == '$') {
      cf.t1++;
    } else {
      cf.t2++;
    }
  }
  freqTuplet curCf;
  for (std::map<char, SuffixNode *>::iterator it = n->children.begin();
       it != n->children.end(); ++it) {
    curCf = getMinUniqueSubstr(it->second, strLen + n->len);
    cf.t1 += curCf.t1;
    cf.t2 += curCf.t2;
  }
  if (cf.t1 == 1 && cf.t2 == 1 &&
      (minDepthWithUniqueSubstr == -1 ||
       strLen + 1 < minDepthWithUniqueSubstr)) {
    minDepthWithUniqueSubstr = strLen + 1;
  }
  return cf;
}
int main(int argc, char *argv[]) {
  minDepthWithUniqueSubstr = -1;
  cin >> text;
  string text2;
  cin >> text2;
  text.append("$");
  text.append(text2);
  text.append("#");
  SuffixNode root;
  root.pos = -1;
  root.len = 0;
  for (short i = 0; i < text.size() - text2.size() - 1; i++) {
    addSuffix(&root, i, text.size() - text2.size() - i - 1);
  }
  for (short i = text.size() - text2.size() - 1; i < text.size(); i++) {
    addSuffix(&root, i, text.size() - i);
  }
  getMinUniqueSubstr(&root, 0);
  cout << minDepthWithUniqueSubstr << endl;
  return 0;
}
