#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int main() {
  cin >> s1 >> s2;
  int len1 = s1.size(), len2 = s2.size();
  if (s1 == s2) {
    cout << "-1";
    return 0;
  }
  cout << max(len1, len2);
  return 0;
}
