#include<bits/stdc++.h> using namespace std; priority_queuepq; int main(){ int n; cin>>n; while(n--){ int x; cin>>x; pq.push(x); } while(pq.size()>1){ int y; y=pq.top(); pq.pop(); y-=pq.top(); pq.pop(); if(y!=0)pq.push(y); } if(pq.empty())cout<<0<<endl; else cout<<pq.top()<<endl; }