#include <bits/stdc++.h>
using namespace std;

#define DEBUG  // comment this line to pull out print statements
#ifdef DEBUG

// completely copied from http://saadahmad.ca/cc-preprocessor-metaprogramming-2/

const char NEWLINE[] = "\n";
const char TAB[] = "\t";

#define EMPTY()
#define DEFER(...) __VA_ARGS__ EMPTY()
#define DEFER2(...) __VA_ARGS__ DEFER(EMPTY) ()
#define DEFER3(...) __VA_ARGS__ DEFER2(EMPTY) ()

#define EVAL_1(...) __VA_ARGS__
#define EVAL_2(...) EVAL_1(EVAL_1(__VA_ARGS__))
#define EVAL_3(...) EVAL_2(EVAL_2(__VA_ARGS__))
#define EVAL_4(...) EVAL_3(EVAL_3(__VA_ARGS__))
#define EVAL_5(...) EVAL_4(EVAL_4(__VA_ARGS__))
#define EVAL_6(...) EVAL_5(EVAL_5(__VA_ARGS__))
#define EVAL_7(...) EVAL_6(EVAL_6(__VA_ARGS__))
#define EVAL_8(...) EVAL_7(EVAL_7(__VA_ARGS__))
#define EVAL(...) EVAL_8(__VA_ARGS__)

#define NOT_0 EXISTS(1)
#define NOT(x) TRY_EXTRACT_EXISTS ( CAT(NOT_, x), 0 )

#define IS_ENCLOSED(x, ...) TRY_EXTRACT_EXISTS ( IS_ENCLOSED_TEST x, 0 )

#define ENCLOSE_EXPAND(...) EXPANDED, ENCLOSED, (__VA_ARGS__) ) EAT (
#define GET_CAT_EXP(a, b) (a, ENCLOSE_EXPAND b, DEFAULT, b )

#define CAT_WITH_ENCLOSED(a, b) a b
#define CAT_WITH_DEFAULT(a, b) a ## b
#define CAT_WITH(a, _, f, b) CAT_WITH_ ## f (a, b)

#define EVAL_CAT_WITH(...) CAT_WITH __VA_ARGS__
#define CAT(a, b) EVAL_CAT_WITH ( GET_CAT_EXP(a, b) )

#define IF_1(true, ...) true
#define IF_0(true, ...) __VA_ARGS__
#define IF(value) CAT(IF_, value)

#define HEAD(x, ...) x
#define TAIL(x, ...) __VA_ARGS__

#define TEST_LAST EXISTS(1)
#define IS_LIST_EMPTY(...) TRY_EXTRACT_EXISTS( DEFER(HEAD) (__VA_ARGS__ EXISTS(1)) , 0)
#define IS_LIST_NOT_EMPTY(...) NOT(IS_LIST_EMPTY(__VA_ARGS__))

#define DOES_VALUE_EXIST_EXISTS(...) 1
#define DOES_VALUE_EXIST_DOESNT_EXIST 0
#define DOES_VALUE_EXIST(x) CAT(DOES_VALUE_EXIST_, x)

#define TRY_EXTRACT_EXISTS(value, ...) IF ( DOES_VALUE_EXIST(TEST_EXISTS(value)) ) \
	( EXTRACT_VALUE(value), __VA_ARGS__ )

#define EXTRACT_VALUE_EXISTS(...) __VA_ARGS__
#define EXTRACT_VALUE(value) CAT(EXTRACT_VALUE_, value)

#define EAT(...)
#define EXPAND_TEST_EXISTS(...) EXPANDED, EXISTS(__VA_ARGS__) ) EAT (
#define GET_TEST_EXISTS_RESULT(x) ( CAT(EXPAND_TEST_, x),  DOESNT_EXIST )

#define GET_TEST_EXIST_VALUE_(expansion, existValue) existValue
#define GET_TEST_EXIST_VALUE(x) GET_TEST_EXIST_VALUE_  x

#define TEST_EXISTS(x) GET_TEST_EXIST_VALUE (  GET_TEST_EXISTS_RESULT(x) )

#define ENCLOSE(...) ( __VA_ARGS__ )
#define REM_ENCLOSE_(...) __VA_ARGS__
#define REM_ENCLOSE(...) REM_ENCLOSE_ __VA_ARGS__

#define IF_ENCLOSED_1(true, ...) true
#define IF_ENCLOSED_0(true, ...) __VA_ARGS__
#define IF_ENCLOSED(...) CAT(IF_ENCLOSED_, IS_ENCLOSED(__VA_ARGS__))

#define OPT_REM_ENCLOSE(...) \
  IF_ENCLOSED (__VA_ARGS__) ( REM_ENCLOSE(__VA_ARGS__), __VA_ARGS__ )

#define FOR_EACH_INDIRECT() FOR_EACH_NO_EVAL
#define FOR_EACH_NO_EVAL(fVisitor, ...) \
  IF ( IS_LIST_NOT_EMPTY( __VA_ARGS__ )  ) \
  ( \
    fVisitor( OPT_REM_ENCLOSE(HEAD(__VA_ARGS__)) ) \
    DEFER2 ( FOR_EACH_INDIRECT )() (fVisitor, TAIL(__VA_ARGS__))	\
  )
#define FOR_EACH(fVisitor, ...) \
  EVAL(FOR_EACH_NO_EVAL(fVisitor, __VA_ARGS__))

#define STRINGIFY(x) #x
#define DUMP_VAR(x) std::cout << STRINGIFY(x) << ": " << x << TAB;

#define debug(...) FOR_EACH(DUMP_VAR, __VA_ARGS__); std::cout << NEWLINE;
#define dbg(block) block
#else
#define debug(...)
#define dbg(block)
#endif

const double EPS = 1E-9;

// --- GEOMETRY ---
// --- points, lines, functions for lines and points, triangles,
// --- circles.
// -- insert geometry.hh here for geometric functions

// --- END GEOMETRY ---

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;

#define UN(v) SORT(v),v.erase(unique(v.begin(),v.end()),v.end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for (int  i=(a); i < (b); i++)
#define REP(i,n) FOR(i,0,(int)n)
#define CL(a,b) memset(a,b,sizeof(a))
#define CL2d(a,b,x,y) memset(a, b, sizeof(a[0][0])*x*y)

/* global variables */
int W, N;
int l, w;
int i, j, k;
char Ws[20], Ns[20];
int total_area;
char line[100];
//char answers[10000][21];
char answers[100000];
int ans, ansb;
int tlen, clen;
/* global variables */

void dump()
{
	// dump data
}

bool getInput()
{
	if (feof(stdin)) return false;

	return true;
}

void process()
{
	// int a = 2, b = 5, c = 3;
	// debug(a, b, c); // debugging example

	// printf("%d\n", total_area/W);
}

int main()
{
	ios_base::sync_with_stdio(false);
	char digits[10];
	fgets_unlocked(line, 99, stdin);
	do
	{
		for (i = 0; line[i] != '\n'; ++i) {
			Ws[i] = line[i];
		}
		Ws[i] = 0;

		for (k = 0; k < i-1; ++k) {
			W += Ws[k]-'0';
			W *= 10;
		}
		W += Ws[k]-'0';

		fgets_unlocked(line, 99, stdin);

		for (j = 0; line[j] != '\n'; ++j) {
			Ns[j] = line[j];
		}

		for (k = 0; k < j-1; ++k) {
			N += Ns[k]-'0';
			N *= 10;
		}
		N += Ns[k]-'0';
		REP(counter, N) {
			l = w = 0;
			fgets_unlocked(line, 99, stdin);

			for (i = 0; line[i] != ' '; ++i) {
				Ws[i] = line[i];
			}
			Ws[i+1] = 0;

			for (k = 0; k < i-1; ++k) {
				l += Ws[k]-'0';
				l *= 10;
			}
			l += Ws[k]-'0';

			while (line[i] == ' ') {
				++i;
			}
			for (j = 0; line[i] != '\n' && line[i] != 0; ++i, ++j) {
				Ns[j] = line[i];
			}
			Ns[j+1] = 0;

			for (k = 0; k < j-1; ++k) {
				w += Ns[k]-'0';
				w *= 10;
			}
			w += Ns[k]-'0';

			total_area += l*w;
		}

		ans = total_area/W, ansb = ans;
		digits[9] = '\n';
		clen = 9;
		while (ans != 0) {
			digits[--clen] = (ans%10)+'0';
			ans /= 10;
		}
		memcpy(&answers[tlen], &digits[clen], 10-clen);
		tlen += 10-clen;
		/* CLEAR GLOBAL VARIABLES! */
		total_area = 0;
		W = 0;
		N = 0;
		l = 0;
		w = 0;
		/* CLEAR GLOBAL VARIABLES! */

		fgets_unlocked(line, 99, stdin);
	} while (!feof_unlocked(stdin));

	fwrite_unlocked(&answers, sizeof(char), tlen, stdout);

	return 0;
}
