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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  int n, x;  cin >> n >> x;
  vector<int> a(n); cin >> a;
  ll ans = max(0, a[0]-x);
  for (int i = 0; i < n-1; ++i){
    ll now = max (min(a[i]+a[i+1]-x, a[i+1]), 0);
    ans += now;
    a[i+1] -= now;
  }
  cout << ans << "\n";
  return 0;
}
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N; cin >> N;
  vector<ll> a(N); vector<ll> b(N);
  rep(i,N) cin >> a[i] >> b[i];

  ll ans = 0;
  ll hu = 0, k = 0;
  rep(i,N) hu += a[i] * b[i];
  rep(i,N) k += b[i];
  ans = (k - 1) + (hu - 1) / 9;
  cout << ans << endl;
}
