//t1
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 1010;
struct Jf
{
int j;
int f;
//f catfood exchange j javabean.
double ra;
}jf[N];
bool cmp(const Jf &a,const Jf &b)
{
return a.ra > b.ra;
}
int main()
{
int n,m;
while(cin >> m >> n)
{
double ans = 0.0;
if(m == -1 && n == -1)break;
for(int i = 0;i < n;i++)
{
cin >> jf[i].j >> jf[i].f;
jf[i].ra = (double)jf[i].j / (double)jf[i].f;
}
sort(jf,jf + n,cmp);
for(int i = 0;i < n;i++)
{
if(m >= jf[i].f)
{
m -= jf[i].f;
ans += jf[i].j;
}
else if(m < jf[i].f)
{
ans += (double)m * jf[i].ra;
break;
}
}
printf("%.3lf\n",ans);
}
return 0;
}
//t4
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 110;
struct temp
{
int st;
int ed;
}time[N];
bool cmp(const temp &a,const temp &b)
{
if(a.ed != b.ed)return a.ed < b.ed;
}
int main()
{
int n;
while(cin >> n && n != 0)
{
int cnt = 1;
for(int i = 0;i < n;i++)
{
scanf("%d%d",&time[i].st,&time[i].ed);
}
sort(time,time + n,cmp);
int stti = time[0].ed;
for(int i = 1;i < n;i++)
{
if(stti <= time[i].st)
{
stti = time[i].ed;
cnt++;
}
}
printf("%d\n",cnt);
}
return 0;
}
//t3
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 10010;
struct teMp
{
int l;
int r;
bool flag;
}lr[N];
bool cmp(const teMp &a,const teMp &b)
{
if(a.l != b.l)return a.l < b.l;
else return a.r < b.r;
}
int main()
{
int t;
scanf("%d",&t);
while(t -- )
{
int n;
scanf("%d",&n);
int cnt = 0;
for(int i = 0;i < n;i++)
{
scanf("%d%d",&lr[i].l,&lr[i].r);
lr[i].flag = 0;
}
sort(lr,lr + n,cmp);
for(int i = 0;i < n;i++)
{
if(lr[i].flag == 1)continue;
lr[i].flag = 1;
int temp = i;
cnt++;//new a group,so cnt add;
for(int j = i + 1;j < n;j++)
{
if(lr[j].flag == 1)continue;
else if(lr[j].flag == 0)
{
if(lr[j].l >= lr[temp].l && lr[j].r >= lr[temp].r)
{
//mark and update
lr[j].flag = 1;
temp = j;
}
}
}
}
printf("%d\n",cnt);
}
return 0;
}
//t2
#include <iostream>
#include <algorithm>
#include <cstring>
int main()
{
int l[401],r[401],a[401];
int t,n,maxnum;
scanf("%d",&t);
while(t -- )
{
scanf("%d",&n);
for(int i = 0;i <= 400;i++)a[i] = 0;
for(int i = 0;i < n;i++)
{
scanf("%d%d",&l[i],&r[i]);
if(l[i] > r[i])
{
int temp = l[i];
l[i] = r[i];
r[i] = temp;
}
if(l[i] % 2 == 0)l[i] = l[i] / 2;
else if(l[i] % 2 == 1)l[i] = (l[i] + 1) / 2;
if(r[i] % 2 == 0)r[i] = r[i] / 2;
else if(l[i] % 2 == 1)r[i] = (r[i] + 1) / 2;
for(int i = l[i];i <= r[i];i++)a[i]++;
}
maxnum = a[1];
for(int i = 2;i <= 200;i++)
if(a[i] > maxnum)maxnum = a[i];
printf("%d\n",10 * maxnum);
}
return 0;
}