#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  string a, b;
  cin >> a >> b;
  if (a == b) {
    cout << -1;
  } else {
    cout << ((a.length()) > (b.length()) ? (a.length()) : (b.length()));
  }
  return 0;
}
