#include<iostream>
#include<algorithm>
#include<cctype>
using namespace std;

bool isValid(string s) {
    if (s.empty()) return false;
    for (char ch : s) {
        if (!isalpha(ch))
        return false;
    }
    return true;
}

int main() {
    string str1, str2;
    getline(cin str1);
    getline(cin, str2);
    
    if (!isValid(str1) || !isValid(str2)) {
        cout << "Invalid input";
        return 0;
    }
    
    transform(str1.begin(), str1.end(), str2.begin(), ::tolower);
    transform(str2.begin(), str2.end(), str2.begin(), ::tolower);
    
    sort(str1.begin(), str1.end());
    sort(str2.begin(), str2.end());
    
    if (str1 == str2)
      cout<< "Anagrams";
    else
      cout<< "Not Anagram";
    return 0;  
}