#include <bits/stdc++.h>
int main() {
  long long int n, i, j, k, m, l, r, f, t, b, q, c1 = 0, c2 = 0, p;
  char s1[200000], s2[200000];
  scanf("%s%s", s1, s2);
  n = strlen(s1);
  m = strlen(s2);
  p = strcmp(s1, s2);
  if (p != 0) {
    if (m >= n)
      printf("%lld", m);
    else
      printf("%lld", n);
  } else
    printf("-1");
}
