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:
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

#define EPS (1e-9)
#define eq(a, b) (fabs(a)-fabs(b) < EPS)
#define lt(a, b) ((a)-(b) < -EPS)
#define le(a, b) (eq(a, b) || lt(a, b))
#define PI acos(-1)

struct Point {
  double x, y;
  Point(double x=0, double y=0):x(x), y(y){}
  Point operator + (Point p) { return Point(x+p.x, y+p.y); }
  Point operator - (Point p) { return Point(x-p.x, y-p.y); }
  Point operator * (double a) { return Point(x*a, y*a); }
  Point operator / (double a) { return Point(x/a, y/a); }
  double norm() { return x*x+y*y; }
  double abs() { return sqrt(norm()); }
  bool operator < (const Point& p) const {
    return x != p.x ? x < p.x : y < p.y;
  }
  bool operator == (const Point& p) const {
    return eq(x, p.x) && eq(y, p.y);
  }
};
typedef Point Vector;

double norm(Vector v) { return v.x*v.x+v.y*v.y; }
double abs(Vector v) { return sqrt(norm(v)); }
double dot(Vector a, Vector b) { return a.x*b.x+a.y*b.y; }
double cross(Vector a, Vector b) { return a.x*b.y-a.y*b.x; }

#define CCW 1
#define CW -1
#define BACK 2
#define FRONT -2
#define ON 0
int ccw(Point p, Point q, Point r) {
  Vector a = q - p, b = r - p;
  if(cross(a, b) > EPS) return CCW;
  if(cross(a, b) < -EPS) return CW;
  if(dot(a, b) < -EPS) return BACK;
  if(norm(a) < norm(b)) return FRONT;
  return ON;
}

bool intersect(Point p, Point q, Point r, Point s) {
  return (ccw(p,q,r)*ccw(p,q,s)<=0&&ccw(r,s,p)*ccw(r,s,q)<=0);
}

double distance(Point a, Point b) { return abs(a-b); }

double rad2deg(double x) { return x*180 / PI; }
double deg2rad(double x) { return x*PI / 180; }
double angle(Point a, Point b, Point c) {
  Vector v = a - b, w = c - b;
  double alpha = atan2(v.y, v.x), beta = atan2(w.y, w.x);
  if(alpha > beta) swap(alpha, beta);
  double theta = rad2deg(beta - alpha);
  return min(theta, 360-theta);
}

struct Segment {
  Point s, t;
  Segment(Point s, Point t):s(s), t(t){}
};
typedef Segment Line;

Point project(Segment s, Point p) {
  Vector base = s.t - s.s;
  double r = dot(p-s.s, base)/norm(base);
  return s.s + base*r;
}
Point reflect(Segment s, Point p) {
  return p + (project(s, p) - p)*2;
}

bool intersect(Segment s, Segment t) {
  return intersect(s.s, s.t, t.s, t.t);
}

double distanceLP(Line l, Point p) {
  return abs(cross(l.t-l.s, p-l.s)/abs(l.t-l.s));
}
double distanceSP(Segment s, Point p) {
  if(dot(s.t-s.s, p-s.s) < 0.0) return abs(p-s.s);
  if(dot(s.s-s.t, p-s.t) < 0.0) return abs(p-s.t);
  return distanceLP(s, p);
}
double distance(Segment s, Segment t) {
  if(intersect(s, t)) return 0;
  return min(min(distanceSP(s, t.s), distanceSP(s, t.t)),
	     min(distanceSP(t, s.s), distanceSP(t, s.t)));
}
Point crossPoint(Segment s, Segment t) {
  Vector base = t.t - t.s;
  double d1 = abs(cross(base, s.s-t.s));
  double d2 = abs(cross(base, s.t-t.s));
  double k = d1 / (d1 + d2);
  return s.s + (s.t-s.s)*k;
}
Point crossPointLL(Line l, Line m) {
  Vector v = l.t-l.s, w = m.t-m.s;
  double d = cross(v, w);
  if(abs(d) < EPS) return m.s;
  return l.s + v*cross(w, m.t-m.s)*(1/d);
}

struct Circle {
  Point c;
  double r;
  Circle(Point c, double r=0):c(c), r(r){}
};

typedef vector<Point> Pointlist;
Pointlist crossPoints(Circle c, Line l) {
  Pointlist res;
  Vector pr = project(l, c.c);
  if(lt(c.r, abs(c.c-pr))) return res;
  Vector e = (l.t-l.s)/abs(l.t-l.s);
  double base = sqrt(c.r*c.r-norm(pr-c.c));
  res.push_back(pr+e*base);
  if(!eq(base, 0)) res.push_back(pr-e*base);
  return res;
}

Pointlist crossPointsCS(Circle c, Segment s) {
  Pointlist res;
  Pointlist pl = crossPoints(c, s);
  for(Point p : pl) {
    if(ccw(s.s, s.t, p) == ON) res.push_back(p);
  }
  return res;
}

int M, N;
Point P[11], Q[11], C;

double solve(Point p, Segment s, bool flag) {
  double res = 360;
  double r = distance(C, p);
  Circle c(C, r);
  Pointlist pl = crossPointsCS(c, s);
  for(Point q : pl) {
    //cout<<p.x<<" "<<p.y<<" "<<C.x<<" "<<C.y<<" "<<q.x<<" "<<q.y<<endl;
    double tmp = angle(p, C, q);
    //cout<<tmp<<" "<<ccw(C,p,q)<<endl;
    if(flag) {
      if(ccw(C, p, q) == CCW) tmp = 360-tmp;
    } else {
      if(ccw(C, p, q) == CW) tmp = 360-tmp;
    }
    chmin(res, tmp);
  }
  return res;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> M >> N, M || N) {
    rep(i, M) cin >> P[i].x >> P[i].y;
    rep(i, N) cin >> Q[i].x >> Q[i].y;
    cin >> C.x >> C.y;
    double ans = 360;
    rep(i, M) rep(j, N) {
      //cout<<i<<" "<<j<<endl;
      chmin(ans, solve(P[i], Segment(Q[j], Q[(j+1)%N]), true));
    }
    rep(i, N) rep(j, M) {
      //cout<<i<<" "<<j<<endl;
      chmin(ans, solve(Q[i], Segment(P[j], P[(j+1)%M]), false));
    }
    cout << ans << endl;
  }

  return 0;
}