Elements of noncommutative arithmetic I