#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int x, y;
  x = a.length();
  y = b.length();
  map<char, int> M;
  int ans;
  if (a == b)
    cout << "-1\n";
  else
    cout << max(x, y) << endl;
}
