#!/usr/bin/env perl
use strict;
use warnings;

my %vals = (
    1 => "1",
    2 => "2",
    3 => "3",
    4 => "4",
    5 => "5",
    6 => "6",
    7 => "7",
    8 => "8",
    9 => "9",
    one => "1",
    two => "2",
    three => "3",
    four => "4",
    five => "5",
    six => "6",
    seven => "7",
    eight => "8",
    nine => "9",
    );

sub to_int {
    my ($n) = @_; 
    return $vals{$n};
}

my $s = 0;
while (<ARGV>) {
    $_ =~ /(\d|one|two|three|four|five|six|seven|eight|nine)/;
    my $first = $1;
    $_ =~ /.*(\d|one|two|three|four|five|six|seven|eight|nine)/;
    my $last = $1;
    $s += (to_int($first) . to_int($last));
}

print("$s\n");
