#include <bits/stdc++.h>
using namespace std;
char a[113455], b[112345];
int main() {
  while (~scanf("%s%s", &a, &b)) {
    int len1 = strlen(a);
    int len2 = strlen(b);
    if (strcmp(a, b) != 0)
      cout << max(len1, len2) << endl;
    else
      cout << "-1" << endl;
    memset(a, '\0', sizeof(a));
    memset(b, '\0', sizeof(b));
  }
  return 0;
}
