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