#include <cstdio>
#include <vector>
#include <cmath>
struct Point {
double x, y;
Point (double x = 0, double y = 0) : x(x), y(y) { }
static Point read() {
double x, y;
scanf("%lf %lf", &x, &y);
return Point(x, y);
}
bool in_circle(const double r) const {
return x*x+y*y < r*r;
}
};
Point operator -(const Point & left, const Point & right) {
return Point(left.x-right.x, left.y-right.y);
}
Point operator +(const Point & left, const Point & right) {
return Point(left.x+right.x, left.y + right.y);
}
Point operator *(const Point & left, const double right) {
return Point(left.x * right, left.y * right);
}
Point operator *(const double left, const Point & right) {
return right * left;
}
double det(const Point & left, const Point & right) {
return left.x * right.y - left.y * right.x;
}
struct Line {
Point A, B;
Line (const Point & A = Point(), const Point & B = Point()) : A(A), B(B) { }
static Line read() {
return Line(Point::read(), Point::read());
}
Point intersect(const Line & other) const {
return other.A + (other.B-other.A) * (det(other.A - A, B-A) / det(B-A, other.B-other.A));
}
};
int main() {
//freopen("input.txt", "rt", stdin);
double r;
int k;
scanf("%lf %d", &r, &k);
int count = 1+k;
std::vector<Line> v(k);
for (int i = 0; i < (int) v.size(); ++i) {
v[i] = Line::read();
for (int j = 0; j < i; ++j) {
count += v[i].intersect(v[j]).in_circle(r);
}
}
printf("%d", count);
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGNtYXRoPgoKc3RydWN0IFBvaW50IHsKICAgIGRvdWJsZSB4LCB5OwogICAgIAogICAgUG9pbnQgKGRvdWJsZSB4ID0gMCwgZG91YmxlIHkgPSAwKSA6IHgoeCksIHkoeSkgeyB9CiAgICAgCiAgICBzdGF0aWMgUG9pbnQgcmVhZCgpIHsKICAgICAgICBkb3VibGUgeCwgeTsKICAgICAgICBzY2FuZigiJWxmICVsZiIsICZ4LCAmeSk7CiAgICAgICAgcmV0dXJuIFBvaW50KHgsIHkpOwogICAgfQogICAgIAogICAgYm9vbCBpbl9jaXJjbGUoY29uc3QgZG91YmxlIHIpIGNvbnN0IHsKICAgICAgICByZXR1cm4geCp4K3kqeSA8IHIqcjsKICAgIH0KfTsKIApQb2ludCBvcGVyYXRvciAtKGNvbnN0IFBvaW50ICYgbGVmdCwgY29uc3QgUG9pbnQgJiByaWdodCkgewogICAgcmV0dXJuIFBvaW50KGxlZnQueC1yaWdodC54LCBsZWZ0LnktcmlnaHQueSk7Cn0KIApQb2ludCBvcGVyYXRvciArKGNvbnN0IFBvaW50ICYgbGVmdCwgY29uc3QgUG9pbnQgJiByaWdodCkgewogICAgcmV0dXJuIFBvaW50KGxlZnQueCtyaWdodC54LCBsZWZ0LnkgKyByaWdodC55KTsKfQogClBvaW50IG9wZXJhdG9yICooY29uc3QgUG9pbnQgJiBsZWZ0LCBjb25zdCBkb3VibGUgcmlnaHQpIHsKICAgIHJldHVybiBQb2ludChsZWZ0LnggKiByaWdodCwgbGVmdC55ICogcmlnaHQpOwp9CiAKUG9pbnQgb3BlcmF0b3IgKihjb25zdCBkb3VibGUgbGVmdCwgY29uc3QgUG9pbnQgJiByaWdodCkgewogICAgcmV0dXJuIHJpZ2h0ICogbGVmdDsKfQogCmRvdWJsZSBkZXQoY29uc3QgUG9pbnQgJiBsZWZ0LCBjb25zdCBQb2ludCAmIHJpZ2h0KSB7CiAgICByZXR1cm4gbGVmdC54ICogcmlnaHQueSAtIGxlZnQueSAqIHJpZ2h0Lng7Cn0KIApzdHJ1Y3QgTGluZSB7CiAgICBQb2ludCBBLCBCOwogICAgIAogICAgTGluZSAoY29uc3QgUG9pbnQgJiBBID0gUG9pbnQoKSwgY29uc3QgUG9pbnQgJiBCID0gUG9pbnQoKSkgOiBBKEEpLCBCKEIpIHsgfQogICAgIAogICAgc3RhdGljIExpbmUgcmVhZCgpIHsKICAgICAgICByZXR1cm4gTGluZShQb2ludDo6cmVhZCgpLCBQb2ludDo6cmVhZCgpKTsKICAgIH0KICAgICAKICAgIFBvaW50IGludGVyc2VjdChjb25zdCBMaW5lICYgb3RoZXIpIGNvbnN0IHsKICAgICAgICByZXR1cm4gb3RoZXIuQSArIChvdGhlci5CLW90aGVyLkEpICogKGRldChvdGhlci5BIC0gQSwgQi1BKSAvIGRldChCLUEsIG90aGVyLkItb3RoZXIuQSkpOwogICAgfQp9OwogCmludCBtYWluKCkgewogICAgLy9mcmVvcGVuKCJpbnB1dC50eHQiLCAicnQiLCBzdGRpbik7CiAgICAgCiAgICBkb3VibGUgcjsKICAgIGludCBrOwogICAgc2NhbmYoIiVsZiAlZCIsICZyLCAmayk7CiAgICAgCiAgICBpbnQgY291bnQgPSAxK2s7CiAgICBzdGQ6OnZlY3RvcjxMaW5lPiB2KGspOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCAoaW50KSB2LnNpemUoKTsgKytpKSB7CiAgICAgICAgdltpXSA9IExpbmU6OnJlYWQoKTsKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IGk7ICsraikgewogICAgICAgICAgICBjb3VudCArPSB2W2ldLmludGVyc2VjdCh2W2pdKS5pbl9jaXJjbGUocik7CiAgICAgICAgfQogICAgfQogICAgIAogICAgcHJpbnRmKCIlZCIsIGNvdW50KTsKICAgICAKICAgIHJldHVybiAwOyAgIAp9