// Arup Guha
// 4/13/2015
// Solution to 2012 NCPC Problem G: Galactic Warlords

import java.util.*;

public class galactic {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int warlords = stdin.nextInt();
		int lines = stdin.nextInt();

		ArrayList<line> myLines = new ArrayList<line>();

		// Read in the lines.
		for (int i=0; i<lines; i++) {

			// Read in the line.
			int x = stdin.nextInt();
			int y = stdin.nextInt();
			pt start = new pt(x,y);
			x = stdin.nextInt();
			y = stdin.nextInt();
			pt end = new pt(x,y);
			line tmp = new line(start, end);

			// See if this line is already in the list.
			boolean add = true;
			for (int j=0; j<myLines.size(); j++) {
				if (tmp.isSame(myLines.get(j))) {
					add = false;
					break;
				}
			}

			// Add it.
			if (add) myLines.add(tmp);
		}

		// Check if all lines are parallel...
		boolean allParallel = true;
		for (int i=1; i<myLines.size(); i++) {
			if (!myLines.get(0).isParallel(myLines.get(i))) {
				allParallel = false;
				break;
			}
		}

		// Set the current number of infinite spots, and what will get added next/
		int cur=0, add=0;
		if (allParallel) {
			cur = myLines.size()+1;
			add = cur;
		}
		else {
			cur = 2*myLines.size();
			add = 2;
		}


		// Small enough that we can add iteratively until we get enough regions.
		// First cut may double regions; after that, it just adds 2.
		int res = 0;
		if (add < 2) add = 2;

		while (cur < warlords) {
			res++;
			cur += add;
			add = 2;
		}

		// Here is our result.
		System.out.println(res);
	}
}

class pt {

	public int x;
	public int y;

	public pt(int myx, int myy) {
		x = myx;
		y = myy;
	}

	public pt sub(pt other) {
		return new pt(x-other.x, y-other.y);
	}

	public boolean isParallel(pt otherDir) {
		return x*otherDir.y - otherDir.x*y == 0;
	}

	public boolean isZero() {
		return x == 0 && y == 0;
	}
}

class line {

	public pt start;
	public pt end;
	public pt dir;

	public line(pt a, pt b) {
		start = a;
		end = b;
		dir = end.sub(start);
	}

	public boolean isParallel(line other) {
		return this.dir.isParallel(other.dir);
	}

	public boolean isSame(line other) {

		// Can't be the same.
		if (!isParallel(other)) return false;

		// Get direction from a point on other to this line.
		pt newdir = other.start.sub(this.start);
		if (newdir.isZero()) newdir = other.start.sub(this.end);

		// If this new line is the same direction as the old, this and other are identical.
		return newdir.isParallel(dir);
	}
}