#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    // if (abs(a-b)<EPS) return 0;
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
  L() {}
};
ostream &operator<<(ostream &os, const L &a) {
  os << a[0]  << "->" << a[1];
  return os;
}

typedef vector<P> G;
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(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 intersectLS(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 intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(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 intersectSS2(const L &s, const L &t) { // 接しているやつは交差と考えない
  REP(i, 2) {
    if (ccw(s[0], s[1], t[i]) == 0) {
      int c = ccw(s[0],s[1],t[!i]);
      if (s[0] == t[i]) {
        if (c!=-2&&c) return 0;
      } else if (s[1] == t[i]) {
        if (c!=2&&c) return 0;
      } else if (abs(c)==1) return 0;
    }
  }
  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 intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

P projection(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]);
}
P reflection(const L &l, const P &p) {
  return p + P(2,0) * (projection(l, p) - p);
}
double distanceLP(const L &l, const P &p) {
  return abs(p - projection(l, p));
}
double distanceLL(const L &l, const L &m) {
  return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
  if (intersectLS(l, s)) return 0;
  return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double 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) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}
double area(const G& g) {
  double A = 0;
  for (int i = 0; i < g.size(); ++i) {
    A += cross(g[i], next(g, i));
  }
  return A/2;
}
G convex_cut(const G& g, const L& l) {
  G Q;
  REP(i, g.size()) {
    P A = curr(g, i), B = next(g, i);
    if (ccw(l[0], l[1], A) != -1) Q.push_back(A);
    if (ccw(l[0], l[1], A)*ccw(l[0], l[1], B) < 0)
      Q.push_back(crosspoint(L(A, B), l));
  }
  return Q;
}
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////

// 点-凸多角形包含関係
bool convex_contain(const G &g, const P &p) { // 半時計回りを仮定
  REP(i,g.size())
    if (ccw(g[i], next(g, i), p) == -1) return 0;
  return 1;
}
// 凸多角形同士の重なり判定
bool intersectGG(const G &g1, const G &g2) {
  if (convex_contain(g1, g2[0])) return 1;
  if (convex_contain(g2, g1[0])) return 1;
  REP(i,g1.size()) REP(j,g2.size()) {
    if (intersectSS(L(g1[i], next(g1, i)), L(g2[j], next(g2, j)))) return 1;
  }
  return 0;
}
// 凸多角形と点の距離
double distanceGP(const G &g, const P &p) {
  if (convex_contain(g, p)) return 0;
  double res = INF;
  REP(i, g.size()) {
    res = min(res, distanceSP(L(g[i], next(g, i)), p));
  }
  return res;
}
// 垂直二等分線
L bisector(const P &a, const P &b) {
  P A = (a+b)*P(0.5,0);
  return L(A, A+(b-a)*P(0, PI/2));
}
// ボロノイ領域
G voronoi_cell(G g, const vector<P> &v, int s) {
  REP(i, v.size())
    if (i!=s)
      g = convex_cut(g, bisector(v[s], v[i]));
  return g;
}
// 角度関連
double angle(const P &a, const P &b) {        // ベクトルａからみたベクトルｂの角度の計算[0,2pi)
  double ret = arg(b)-arg(a);
  return (ret>=0) ? ret : ret + 2*PI;
}
double angle2(const P &a, const P &b) { // ベクトルaとベクトルbの間の角度
  return min(angle(a,b), angle(b,a));
}
double rtod(double rad) {       // ラジアン→度
  return rad*180/PI;
}
double dtor(double deg) {       // 度→ラジアン
  return deg*PI/180;
}
// ベクトルの回転
P rotate(P p, double ang) {
  return p * P(cos(ang), sin(ang));
}
// 原点周りの直線の回転
L rotate(L l, double ang) {
  return L(rotate(l[0], ang),rotate(l[1], ang));
}

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

Graph segmentArrangement(const vector<L> &ss, vector<P> &ps) {
  for (int i = 0; i < ss.size(); ++i) { // O(n^2)
    ps.push_back( ss[i][0] );
    ps.push_back( ss[i][1] );
    for (int j = i+1; j < ss.size(); ++j)
      if (intersectSS(ss[i], ss[j]))
        ps.push_back( crosspoint(ss[i], ss[j]) );
  }
  sort(ALL(ps)); ps.erase(unique(ALL(ps)), ps.end());

  Graph g(ps.size());
  for (int i = 0; i < ss.size(); ++i) {
    vector< pair<double, int> > list;
    for (int j = 0; j < ps.size(); ++j)
      if (intersectSP(ss[i], ps[j]))
        list.push_back(make_pair(norm(ss[i][0]-ps[j]), j));
    sort(ALL(list));
    for (int j = 0; j+1 < list.size(); ++j) {
      int a = list[j].second, b = list[j+1].second;
      g[a].push_back( Edge(a, b, abs(ps[a]-ps[b])) );
      g[b].push_back( Edge(b, a, abs(ps[a]-ps[b])) );
    }
  }
  return g;
}
double manDistanceSP(const L &l, const P &p) {
  double res = INF;
  L xl = L(p, p + P(1,0));
  if (intersectLS(xl, l)){
    P cp = crosspoint(xl, l);
    double d = abs(p-cp);
    res = min(res, d);
  }
  L yl = L(p, p + P(0,1));
  if (intersectLS(yl, l)) {
    P cp = crosspoint(yl, l);
    double d = abs(p-cp);
    res = min(res, d);
  }
  res = min(res, abs(l[0].real()-p.real()) + abs(l[0].imag()-p.imag()));
  res = min(res, abs(l[1].real()-p.real()) + abs(l[1].imag()-p.imag()));
  return res;
}
enum { OUT, ON, IN };
int contains(const G& g, const P& p) {
  bool in = false;
  for (int i = 0; i < g.size(); ++i) {
    P a = curr(g,i) - p, b = next(g,i) - p;
    if (imag(a) > imag(b)) swap(a, b);
    if (imag(a) <= 0 && 0 < imag(b))
      if (cross(a, b) < 0) in = !in;
    if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;
  }
  return in ? IN : OUT;
}

int main() {
  int n, r;
  while(cin>>n>>r, n||r) {
    G p(n);
    REP(i,n) {
      cin >> p[i].real() >> p[i].imag();
    }
    
    double dx[] = {-r,0,r,0};
    double dy[] = {0,r,0,-r};

    vector<L> ss;
    REP(i,n) {
      REP(k,4) {
        P p1 = p[i] + P(dx[k],dy[k]);
        P p2 = p[(i+1)%n] + P(dx[k],dy[k]);
        ss.push_back(L(p1,p2));
        P p3 = p[i] + P(dx[(k+1)%4], dy[(k+1)%4]);
        ss.push_back(L(p1,p3));
      }
    }

    vector<P> ps;
    Graph g = segmentArrangement(ss, ps);
    int m = g.size();
    vector<L> vl;
    map<pii,bool> mp;
    REP(i, m) {
      FOR(jt, g[i]) {
        int a = jt->src;
        int b = jt->dst;

        if (a>b) continue;
        // cout << "line(" << ps[a].real()/50+250 << "," << ps[a].imag()/50+250 <<
        // "," << ps[b].real()/50+250 << "," << ps[b].imag()/50+250 << ")" << endl;      
        double mi = INF;
        REP(j, n) {
          double d = manDistanceSP(L(p[j], p[(j+1)%n]), (ps[a]+ps[b])*0.5);
          mi = min(d, mi);
        }
        //cout << ps[a] << " " << ps[b] << " -> " << (ps[a]+ps[b])*0.5 << " " << mi << endl; 
        if (mi+EPS >r) {
          
          if (mp.count(pii(a,b)) == 0) {
            mp[pii(a,b)] = 1;
            vl.push_back(L(ps[a], ps[b]));
          }
        }
      }
    }

    double len = 0;
    //vector<L> ans;
    FOR(it, vl) {
      if (contains(p, (*it)[0])) {
        //cout << *it << endl;
        len += abs((*it)[0]-(*it)[1]);
        //ans.push_back(*it)
      }
      // cout << "line(" << (*it)[0].real()/50+250 << "," << (*it)[0].imag()/50+250 <<
      //   "," << (*it)[1].real()/50+250 << "," << (*it)[1].imag()/50+250 << ")" << endl;      
    }
    printf("%.10f\n", len);
  }
}

Measured memory_bytes: 1372