#include <string>#include <stdio.h>#include <iostream>#include <string.h>#include <set>#include <math.h>#include <stdlib.h>//using namespace std;struct type { float javabean,food; float leve;}num[1010];int cmp(const void *x, const void *y){ return (*(type *)x).leve > (* (type *) y).leve ? -1:1 ;}int main(){ int m,n; while( ~scanf("%d%d", &m, &n) && m != -1) { for(int i=0; i<n; i++) { scanf("%f%f", &num[i].javabean, &num[i].food); num[i].leve = num[i].javabean /num[i].food; } qsort(num, n, sizeof(type), cmp); float max=0; for(int i=0; i<n; i++) { if(m < num[i].food ) { max += m /num[i].food * num[i].javabean; break; } else { max += num[i].javabean; m -= num[i].food; } } printf("%.3f
", max); } return 0;}