#include<iostream>
using namespace std;
int main()
{
int b, c, x, y, i;
while(cin >> x >> y)
{
if(x == 0 && y == 0)
{
break;
}
int a[y];
for(i=0;i<y;i++)
{
cin >> a[i];
}
b = x - a[0];
if(a[0] > a[1])
{
c = a[0] - a[1];
b = b + c;
}
c = 0;
for(i=1;i<y-1;i++)
{
if(a[i] > a[i+1])
{
c = a[i] - a[i+1];
b = b + c;
}
}
cout << b << "\n";
b=c= 0;
}
return 0;
}
using namespace std;
int main()
{
int b, c, x, y, i;
while(cin >> x >> y)
{
if(x == 0 && y == 0)
{
break;
}
int a[y];
for(i=0;i<y;i++)
{
cin >> a[i];
}
b = x - a[0];
if(a[0] > a[1])
{
c = a[0] - a[1];
b = b + c;
}
c = 0;
for(i=1;i<y-1;i++)
{
if(a[i] > a[i+1])
{
c = a[i] - a[i+1];
b = b + c;
}
}
cout << b << "\n";
b=c= 0;
}
return 0;
}
Comments
Post a Comment