#include <bits/stdc++.h>
using namespace std;
char arr[1001];
vector<int> v1;
using namespace std;
int main() {
  string x, y;
  cin >> x >> y;
  int ans = 0;
  int sz1 = (int)(x.size());
  int sz2 = (int)(y.size());
  int sz = max(sz1, sz2);
  if (x == y) {
    cout << -1;
  } else
    cout << sz;
  return 0;
}
