#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T b, T p, T M) {
  long long ret = 1;
  for (; p > 0; p >>= 1) {
    if (p & 1) ret = (ret * b) % M;
    b = (b * b) % M;
  }
  return (T)ret;
}
int gcd_euclid(int a, int b, int &x, int &y) {
  if (a == 0) {
    x = 0, y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcd_euclid(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
template <class T>
inline T __lcm(T a, T b) {
  return (a * b) / __gcd(a, b);
}
int inGrid(int x, int y, int r, int c) {
  return (x >= 0 && x < r && y >= 0 && y < c ? 1 : 0);
}
int dx4[] = {1, 0, -1, 0};
int dy4[] = {0, 1, 0, -1};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
int rw[] = {0, 0, 1, -1, 0, 0};
int cl[] = {1, -1, 0, 0, 0, 0};
int hi[] = {0, 0, 0, 0, 1, -1};
struct data {
  int u, v, w;
  data() {}
  data(int _u, int _v, int _w) { u = _u, v = _v, w = _w; }
  bool friend operator<(data a, data b) { return a.w < b.w; }
};
const double PI = acos(-1.0), EPS = 1e-7;
const long long INF = 1e18;
const int N = 1e6 + 5, M = 1e9 + 7, NIL = -1;
int main() {
  string s, t;
  cin >> s >> t;
  if (s == t)
    puts("-1");
  else
    cout << max(s.size(), t.size()) << endl;
  return 0;
}
