#include <bits/stdc++.h>
using namespace std;

int main() {
long long n,a;
cin>>n;
a=n;
int k;
cin>>k;
int counter1,counter2,counter=0,;
while(n>0){
n/=10;
counter++;}
while(n>0){
n/=10;
counter++;}
if(k=1){
counter2=counter;
while(counter>1){
a/=10;
counter--;}
cout<<(counter2-1)*9+a<<endl;}
else if(k=2)
if(counter==n){
cout<<"APPROVED"<<endl;}
else{
cout<<"DENIED"<<endl;}}
