#include <bits/stdc++.h>
using namespace std;
using db = double;
constexpr db eps = 1e-6;
int cmp(db a, db b) {
if (a - b > eps) {
return 1;
}
if (a - b < -eps) {
return -1;
}
return 0;
}
struct Point {
db x, y;
Point operator+(const Point& a) {
return {x + a.x, y + a.y};
}
Point operator-(const Point& a) {
return {x - a.x, y - a.y};
}
Point operator*(const db& a) {
return {x * a, y * a};
}
Point operator/(const db& a) {
return {x / a, y / a};
}
};
db dis(Point a, Point b) {
return hypot(a.x - b.x, a.y - b.y);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
db s;
int n;
cin >> s >> n;
vector<Point> A(n);
for (auto &[x, y] : A) {
cin >> x >> y;
}
vector<db> sum(n);
vector<db> tim;
for (int i = 0; i < n - 1; i++) {
sum[i + 1] = sum[i] + dis(A[i], A[i + 1]);
}
for (int i = 0; i < n; i++) {
if (cmp(sum[i] + s, sum[n - 1]) <= 0) {
tim.push_back(sum[i]);
}
if (cmp(sum[i], s) >= 0) {
tim.push_back(sum[i] - s);
}
}
sort(tim.begin(), tim.end());
int i1 = 0, i2 = 0;
Point dir1, dir2;
auto calc = [&](db t) {
Point a = A[i1] + dir1 * (t - sum[i1]);
Point b = A[i2] + dir2 * (t + s - sum[i2]);
return dis(a, b);
};
db ans = 1e18;
for (int i = 0; i < tim.size() - 1; i++) {
db t1 = tim[i], t2 = tim[i + 1];
if (cmp(t1, t2) == 0 || cmp(t1, s[n - 1]) == 1 || cmp(t2, s[n - 1]) == 1 || cmp(t1, s) == -1 || cmp(t2, s) == -1) {
continue;
}
while (cmp(sum[i1], t1) <= 0) {
i1++;
}
while (cmp(sum[i2], t1 + s) <= 0) {
i2++;
}
i1--, i2--;
dir1 = (A[i1 + 1] - A[i1]) / dis(A[i1 + 1], A[i1]);
dir2 = (A[i2 + 1] - A[i2]) / dis(A[i2 + 1], A[i2]);
while (t2 - t1 > eps) {
db lm = (2 * t1 + t2) / 3;
db rm = (t1 + 2 * t2) / 3;
if (calc(lm) > calc(rm)) {
t1 = lm;
} else {
t2 = rm;
}
}
ans = min(ans, calc(t1));
}
cout << ans << "\n";
return 0;
}