#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define INF 0x3f3f3f3f typedef long long LL; const int N=100005; const int mod=1e9+7; LL a[N],b[N]; LL p[1005],k[1005]; LL dp[1005][15]; int main() { int n,m; while (cin>>n>>m) { LL att,def,hp; att=def=hp=0; for (int i=1; i<=n; i++) { scanf("%I64d %I64d",&a[i],&b[i]); def=max(def, b[i]); hp=max(a[i], hp); } for (int i=1; i<=m; i++) { scanf("%I64d %I64d",&k[i],&p[i]); att=max(att, p[i]); } if (def>=att) { cout<<"-1"<