#include <bits/stdc++.h>
using namespace std;
long long int lsone(long long int p) { return (p & -p); }
string s1, s2;
int main() {
  std::ios::sync_with_stdio(false);
  cin >> s1;
  cin >> s2;
  if (s1 == s2)
    cout << -1;
  else
    cout << max(s1.size(), s2.size());
}
