#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  if (n == m && s == t)
    cout << -1;
  else
    cout << max(n, m);
}
