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