Problem: HCII, the health committee for interstellar intelligence, aims to take care of the health of every interstellar intelligence.

Staff of HCII uses a special equipment for health checks of patients. This equipment looks like a polygon-shaped room with plenty of instruments. The staff puts a patient into the equipment, then the equipment rotates clockwise to diagnose the patient from various angles. It fits many species without considering the variety of shapes, but not suitable for big patients. Furthermore, even if it fits the patient, it can hit the patient during rotation.

<image>

Figure 1: The Equipment used by HCII

The interior shape of the equipment is a polygon with M vertices, and the shape of patients is a convex polygon with N vertices. Your job is to calculate how much you can rotate the equipment clockwise without touching the patient, and output the angle in degrees.



Input

The input consists of multiple data sets, followed by a line containing “0 0”. Each data set is given as follows:


M N
px1 py1 px2 py2 ... pxM pyM
qx1 qy1 qx2 qy2 ... qxN qyN
cx cy


The first line contains two integers M and N (3 ≤ M, N ≤ 10). The second line contains 2M integers, where (pxj , pyj ) are the coordinates of the j-th vertex of the equipment. The third line contains 2N integers, where (qxj , qyj ) are the coordinates of the j-th vertex of the patient. The fourth line contains two integers cx and cy, which indicate the coordinates of the center of rotation.

All the coordinates are between -1000 and 1000, inclusive. The vertices of each polygon are given in counterclockwise order.

At the initial state, the patient is inside the equipment, and they don’t intersect each other. You may assume that the equipment doesn’t approach patients closer than 10-6 without hitting patients, and that the equipment gets the patient to stick out by the length greater than 10-6 whenever the equipment keeps its rotation after hitting the patient.

Output

For each data set, print the angle in degrees in a line. Each angle should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-7 .

If the equipment never hit the patient during the rotation, print 360 as the angle.

Example

Input

5 4
0 0 20 0 20 10 0 10 1 5
10 3 12 5 10 7 8 5
10 5
4 3
0 0 10 0 10 5 0 5
3 1 6 1 5 4
0 0
5 3
0 0 10 0 10 10 0 10 3 5
1 1 4 1 4 6
0 0
0 0


Output

360.0000000
12.6803835
3.3722867

Solution (in CPP):

Solution:
// ぶつかるとき頂点が辺に 触れる
// 内側の点がぶつからずにどこまで行けるか
// 外側の点がぶつからずにどこまで行けるか
//  のminをとる

#include <complex>
#include <algorithm>
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

typedef double R;

#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};

const R eps = 1e-8;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
namespace std {
    bool operator < (const P& a, const P& b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
    template<typename T>
    ostream& operator<<(ostream& os, const vector<T> v){
        for(auto const& p : v) os << p << ",";
        return os;
    }
}
R cross(const P& a, const P& b) {
    return imag(conj(a)*b);
}
R dot(const P& a, const P& b) {
    return real(conj(a)*b);
}

struct L : public vector<P> {
    // A to B
    L(const P &A, const P &B) {
        push_back(A); push_back(B);
    }
    // ax+by+c=0
    L(R a, R b, R c){
        if(fabs(a) < eps) *this = L(P(0,-c/b),P(1,-c/b));
        else if(fabs(b) < eps) *this = L(P(-c/a,0),P(-c/a,1));
        else *this = L(P(-c/a,0), P(0,-c/b));
    }
};

typedef vector<P> G;

struct C {
    P p; R r;
    C(const P &p, R r) : p(p), r(r) { }
    C(){}
};

// CCW
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SAMEPOINT = 0 };
int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if (cross(b, c) > 0)   return CCW; // a->b->c 反時計回り
    if (cross(b, c) < 0)   return  CW; // a->b->c 時計回り
    if (dot(b, c) < 0)     return CAB; // c--a--b 直線上
    if (norm(b) < norm(c)) return ABC; // a--b--c 直線上
    return SAMEPOINT; // 2点以上が重なっている
}

// 交差判定
bool colLL(const L &l, const L &m) {
    return
        abs(cross(l[1]-l[0], m[1]-m[0])) > eps || // non-parallel
        abs(cross(l[1]-l[0], m[0]-l[0])) < eps;   // same line
}

bool colLS(const L &l, const L &s) {
    return
        cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
        cross(l[1]-l[0], s[1]-l[0]) < eps; // s[1] is right of l
}

bool colLP(const L &l, const P &p) {
    return abs(cross(l[1]-p, l[0]-p)) < eps;
}

bool colSS(const L &s, const L &t) {
    return
        ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
        ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

bool colSP(const L &s, const P &p) {
    return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < eps; // triangle inequality
}

bool colCP(const C &c, const P &p) {
    // 境界または内部
    return abs(c.p - p) <= c.r + eps;
}

int colCC(const C& c1, const C& c2){
    double d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
    if(abs(d - r1 - r2) < eps) return  1; // 接する
    if(d > r1 + r2)       return  0; // 共通部分を持たない
    if(d < r1 - r2)       return +3; // c1 が c2 の中にある
    if(d < r2 - r1)       return -3; // c2 が c1 の中にある
    return 2; // 2つの交点を持つ
}

// 射影
P projLP(const L &l, const P &p) {
    double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
    return l[0] + t*(l[0]-l[1]);
}
L projLL(const L& l, const L& m) {
    return L(projLP(l,m[0]), projLP(l,m[1]));
}

// 反射
P reflLP(const L &l, const P &p) {
    return p + 2. * (projLP(l, p) - p);
}
L reflLL(const L& l, const L& m) {
    return L(reflLP(l,m[0]), reflLP(l,m[1]));
}

// 距離
R distLP(const L &l, const P &p) {
    return abs(p - projLP(l, p));
}

R distLL(const L &l, const L &m) {
    return colLL(l, m) ? 0 : distLP(l, m[0]);
}

R distLS(const L &l, const L &s) {
    if (colLS(l, s)) return 0;
    return min(distLP(l, s[0]), distLP(l, s[1]));
}

R distSP(const L &s, const P &p) {
    const P r = projLP(s, p);
    if (colSP(s, r)) return abs(r - p);
    return min(abs(s[0] - p), abs(s[1] - p));
}

R distSS(const L &s, const L &t) {
    if (colSS(s, t)) return 0;
    return min(min(distSP(s, t[0]), distSP(s, t[1])),
               min(distSP(t, s[0]), distSP(t, s[1])));
}

R distCP(const C &c, const P &p) {
    return max(0. , abs(c.p - p));
}

// positive -> outside
// zero     -> on the boundaly
// negative -> inside
R distCL(const C& c, const L& l){
    R d = distLP(l,c.p);
    return d - c.r;
}

// 交点
vector<P> intLL(const L &l, const L &m) {
    R A = cross(l[1] - l[0], m[1] - m[0]);
    R B = cross(l[1] - l[0], l[1] - m[0]);
    if (abs(A) < eps && abs(B) < eps) return {m[0]}; // same line
    if (abs(A) < eps) return {}; // parallel
    return {m[0] + B / A * (m[1] - m[0])};
}

vector<P> intSS(const L& s, const L& t) {
    if(colSS(s,t)) return intLL(s,t);
    return {};
}

vector<P> intLS(const L& l, const L& s){
    if(colLS(l,s)) return intLL(l,s);
    return {};
}

// Verify : http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1183
vector<P> intCL(const C& c, const L& l){
    R d = distLP(l,c.p); // 中心と直線の距離
    if(fabs(d-c.r) < eps) return { projLP(l, c.p) }; // 触れている
    if(d > c.r) return {}; // 離れている
    P h = projLP(l, c.p);
    P u = sqrt(c.r*c.r - d*d) * (l[0]-l[1]) / abs(l[0]-l[1]);
    return {h+u, h-u};
}

// Verify : http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1183
vector<P> intCC(const C& c1, const C& c2){
    int i = colCC(c1,c2);
    if(i==0 || abs(i)==3) return {}; // no common area || inner
    R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
    if(i==1) return { c1.p + (c2.p - c1.p) * r1/d }; // touching
    P p = c1.p - c2.p;
    R A = -2. * p.real(), B = 2 * p.imag(), C = norm(c1.p) - norm(c2.p) - r1*r1 + r2*r2;
    return intCL(c1, L(A,B,C));
}

vector<P> intCS(const C& c, const L& s){
    vector<P> cs = intCL(c,s), res;
    for(const P& p : cs) {
        if(colSP(s,p)) res.push_back(p);
    }
    return res;
}


// 角ABCの大きさ
R arg(P a, P b, P c) {
    R th = arg((a - b) / (c - b));
    return th > 0 ? th : th+2*pi;
}

int M,N;
G out,in;
P c;

int cnt;
R solve(){
    R ans = pi*2;
    rep(k,2){
        rep(i,out.size()-1){
            rep(j,in.size()-1){
                C cir(c,abs(c-in[j]));
                if(cir.r < eps) continue;
                L seg(out[i],out[i+1]);
                // dump(i,i+1);
                // dump(seg);
                // dump(cir.r, cir.p);
                vector<P> cps = intCS(cir, seg);
                // dump(cps);
                for(auto cp : cps){
                    double th;
                    if(k==1)th = arg(in[j], cir.p, cp);
                    if(k==0)th = arg(cp,    cir.p, in[j]);
                    // dump(th/pi*180);
                    ans = min(ans,th);
                }
            }
        }
        swap(in,out);
    }
    return ans*180/pi;
}

int main(){
    cnt=0;
    while(cin>>M>>N && M){
        cnt++;
        out.resize(M+1);
        in.resize(N+1);
        rep(i,M){
            R x,y;
            cin>>x>>y;
            out[i] = P(x,y);
        }
        rep(i,N){
            R x,y;
            cin>>x>>y;
            in[i] = P(x,y);
        }
        out.back() = out.front();
        in.back() = in.front();
        double x,y;
        cin>>x>>y;
        c = P(x,y);
        printf("%.10lf\n",solve());
    }
}