#include <bits/stdc++.h>
using namespace std;
int reader_pt = 1048576, reader_last;
char reader_buf[1048576];
int writer_pt = 0;
char writer_buf[1048576];
int reader(char c[]) {
  int i, s = 0;
  for (;;) {
    {
      if (reader_pt == 1048576)
        reader_pt = 0,
        reader_last = fread(reader_buf, sizeof(char), 1048576, stdin);
      (i) = reader_buf[reader_pt++];
    };
    if (i != ' ' && i != '\n' && i != '\r' && i != '\t') break;
  }
  c[s++] = i;
  for (;;) {
    {
      if (reader_pt == 1048576)
        reader_pt = 0,
        reader_last = fread(reader_buf, sizeof(char), 1048576, stdin);
      (i) = reader_buf[reader_pt++];
    };
    if (i == ' ' || i == '\n' || i == '\r' || i == '\t') break;
    c[s++] = i;
  }
  return s;
}
void writer(int x, char c) {
  int i, sz = 0, m = 0;
  char buf[10];
  if (x < 0) m = 1, x = -x;
  while (x) buf[sz++] = x % 10, x /= 10;
  if (!sz) buf[sz++] = 0;
  if (m) {
    if (writer_pt == 1048576)
      writer_pt = 0, fwrite(writer_buf, sizeof(char), 1048576, stdout);
    writer_buf[writer_pt++] = ('-');
  };
  while (sz--) {
    if (writer_pt == 1048576)
      writer_pt = 0, fwrite(writer_buf, sizeof(char), 1048576, stdout);
    writer_buf[writer_pt++] = (buf[sz] + '0');
  };
  {
    if (writer_pt == 1048576)
      writer_pt = 0, fwrite(writer_buf, sizeof(char), 1048576, stdout);
    writer_buf[writer_pt++] = (c);
  };
}
template <class T>
struct ullHash {
  unsigned long long *key;
  T *val;
  unsigned memory, size, mask;
  void clear() { memset(val, 0, size * sizeof(T)); }
  void clear(int sz) {
    size = 1;
    while (size < sz) size *= 2;
    mask = size - 1;
    clear();
  }
  void init(int mem, int sz) {
    memory = mem;
    size = 1;
    while (size < sz) size *= 2;
    mask = size - 1;
    if (memory < size) memory = size;
    key = (unsigned long long *)malloc(memory * sizeof(unsigned long long));
    val = (T *)malloc(memory * sizeof(T));
    if (size) clear();
  }
  int function(unsigned long long a) { return (a * 97531) & mask; }
  T get(unsigned long long a) {
    int i = function(a);
    for (; key[i] != a && val[i] != 0;) i = (i + 1) & mask;
    if (key[i] != a) return 0;
    return val[i];
  }
  void set(unsigned long long a, T v) {
    int i = function(a);
    for (; key[i] != a && val[i] != 0;) i = (i + 1) & mask;
    key[i] = a;
    val[i] = v;
  }
  T increase(unsigned long long a, T v = 1) {
    int i = function(a);
    for (; key[i] != a && val[i] != 0;) i = (i + 1) & mask;
    key[i] = a;
    return val[i] += v;
  }
};
unsigned long long pw[5010];
int main() {
  char a[10000], b[10000];
  int as, bs;
  int i, j, k, res;
  ullHash<int> hash;
  unsigned long long hs;
  hash.init(16000, 16000);
  pw[0] = 1;
  for (i = 1; i < 5010; i++) pw[i] = pw[i - 1] * 13579;
  as = reader(a);
  bs = reader(b);
  res = -1;
  for (k = 1; k < as + 1; k++) {
    if (k > bs) break;
    hash.clear();
    hs = 0;
    for (i = 0; i < k; i++) hs = hs * 13579 + a[i];
    hash.increase(hs);
    for (i = k; i < as; i++) {
      hs = hs * 13579 + a[i] - pw[k] * a[i - k];
      hash.increase(hs);
    }
    hs = 0;
    for (i = 0; i < k; i++) hs = hs * 13579 + b[i];
    hash.increase(hs, 10000);
    for (i = k; i < bs; i++) {
      hs = hs * 13579 + b[i] - pw[k] * b[i - k];
      hash.increase(hs, 10000);
    }
    hs = 0;
    for (i = 0; i < k; i++) hs = hs * 13579 + a[i];
    if (hash.get(hs) == 10001) {
      res = k;
      break;
    }
    for (i = k; i < as; i++) {
      hs = hs * 13579 + a[i] - pw[k] * a[i - k];
      if (hash.get(hs) == 10001) {
        res = k;
        break;
      }
    }
    if (res != -1) break;
  }
  writer(res, '\n');
  {
    fwrite(writer_buf, sizeof(char), writer_pt, stdout);
    writer_pt = 0;
  };
  return 0;
}
