#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, s2;
  cin >> s1;
  cin >> s2;
  int maxl = max(s1.length(), s2.length());
  for (int i = s1.length(); i < maxl; i++) s1 += "0";
  for (int i = s2.length(); i < maxl; i++) s2 += "0";
  for (int i = 0; i < maxl; i++) {
    if (s1[i] != s2[i]) {
      cout << maxl << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
