#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void){

	string roman;
	string fig("IVXLCDM");
	int ure[]={1,5,10,50,100,500,1000};
	int sum;
	while(cin>>roman){
		sum=0;
		for(int i=1;i<roman.length();i++){
			if(ure[fig.find(roman[i])]>ure[fig.find(roman[i-1])]) sum+=-1*ure[fig.find(roman[i-1])];
			else sum+=ure[fig.find(roman[i-1])];
		}
		sum+=ure[fig.find(roman[roman.length()-1])];
		cout<<sum<<endl;
	}

	return 0;
}
#include <iostream>
using namespace std;
int gcd(int a, int b){
    if(a < b) swap(a,b);
    if(b == 0) return a;
    else return gcd(b, a%b);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    if(N == 2){
        int a, b;
        cin >> a >> b;
        for(int i = 1; i < max(a,b) + 1; ++i){
            if(a%i == 0 && b%i == 0) cout << i << endl;
        }
    }
    else {
        int a, b , c;
        cin >> a >> b >> c;
        for(int i = 1; i < max(a,max(b,c)) + 1; ++i){
            if(a%i == 0 && b%i == 0 && c%i == 0) cout << i << endl;
        }
    }
    return 0;
}
