#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  string a;
  string b;
  cin >> a >> b;
  if (a == b) {
    cout << -1 << "\n";
  } else if (a.size() > b.size()) {
    cout << a.size() << "\n";
  } else if (b.size() > a.size()) {
    cout << b.size() << "\n";
  } else {
    cout << a.size() << "\n";
  }
}
