#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  string b;
  cin >> a >> b;
  long long int len1 = a.length();
  long long int len2 = b.length();
  if (a.compare(b) == 0) {
    cout << "-1\n";
  } else {
    if (len1 > len2)
      cout << len1 << "\n";
    else
      cout << len2 << "\n";
  }
}
