#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int check(int year){
  if(year % 400 == 0) return 29;
  if(year % 400 != 0 && year % 100 == 0) return 28;
  if(year % 100 !=0 && year % 4 == 0) return 29;
  if(year % 4 != 0) return 28;
  return 0;
}
int bit[10][7] = {{0,1,2,4,5,6},
                      {2,5},
                      {0,2,3,4,6},
                      {0,2,3,5,6},
                      {1,2,3,5},
                      {0,1,3,5,6},
                      {0,1,3,4,5,6},
                      {0,2,5},
                      {0,1,2,3,4,5,6},
                      {0,1,2,3,5,6}};
/*int bit[10][7]={
                {1,1,1,0,1,1,1},//0
                {0,0,1,0,0,1,0},//1
                {1,0,1,1,1,0,1},//2
                {1,0,1,1,0,1,1},//3
                {0,1,1,1,0,1,0},//4
                {1,1,0,1,0,1,1},//5
                {1,1,0,1,1,1,1},//6
                {1,0,1,0,0,1,0},//7
                {1,1,1,1,1,1,1},//8
                {1,1,1,1,0,1,1},//9
              };*/
int num_use[10]={6,2,5,5,4,5,6,3,7,6};
int shine_num[14][10];
bool flag[14][7];
long long int num_hms[43];
long long int num_ymd[57];

int main(){
  int n,K;
  cin >> n >> K;
  for(int i=0; i<=13; i++){
    for(int j=0; j<=6; j++) flag[i][j]=true;
  }
  int digit,pos;
  for(int i=0; i<K; i++){
    cin >> digit >> pos;
    flag[digit][pos] = false;
  }
  int count;
  for(int i=0; i<=13; i++){
    for(int j=0; j<=9; j++){
      count=0;
      for(int k=0; k<num_use[j]; k++){
        if(flag[i][bit[j][k]]) count++;
      }
      shine_num[i][j] = count;
    }
  }
  //時分秒
  int work[14];
  for(int i=0; i<=42; i++) num_hms[i] = 0;
  for(int h=0; h<=23; h++){
    for(int m=0; m<=59; m++){
      for(int s=0; s<=59; s++){
        work[8] = shine_num[8][h/10];
        work[9] = shine_num[9][h%10];
        work[10] = shine_num[10][m/10];
        work[11] = shine_num[11][m%10];
        work[12] = shine_num[12][s/10];
        work[13] = shine_num[13][s%10];
        int tmp_sum=0;
        for(int i=8; i<=13; i++) tmp_sum += work[i];
        num_hms[tmp_sum]++;
      }
    }
  }
  //年月日
  for(int i=0; i<=56; i++) num_ymd[i]=0;
  for(int y=0; y<=9999; y++){
    for(int m=1; m<=12; m++){
      int last;
      if(m==4 || m==6 || m==9 || m==11) last = 30;
      else if(m==2) last = check(y);
      else last = 31;
      for(int d=1; d<=last; d++){
        work[0] = shine_num[0][y/1000];
        work[1] = shine_num[1][y/100%10];
        work[2] = shine_num[2][y/10%10];
        work[3] = shine_num[3][y%10];
        work[4] = shine_num[4][m/10];
        work[5] = shine_num[5][m%10];
        work[6] = shine_num[6][d/10];
        work[7] = shine_num[7][d%10];
        int tmp_sum = 0;
        for(int i=0; i<=7; i++) tmp_sum += work[i];
        num_ymd[tmp_sum]++;
      }
    }
  }
  long long int ans = 0;
  for(int i=0; i<=min(42,n); i++){
    if(n-i > 56) continue;
    ans += num_hms[i]*num_ymd[n-i];
  }
  cout << ans << endl;
  return 0;
}



/*
int bit(int p, int n){
  int sum=0;
    for(int i=0; i<7; i++){
    if(flag[p][i]==false) sum += bit[n][i];
    }
    return sum;
}
vector<long long int> a;
int check(int year){
  if(year % 400 == 0) return 29;
  if(year % 400 != 0 && year % 100 == 0) return 28;
  if(year % 100 !=0 && year % 4 == 0) return 29;
  if(year % 4 != 0) return 28;
  return 0;
}

int search(int res,int n){
  int left = 0;
  int right = a.size();
  int mid;
  int x = n-res;
  while(left<right){
    mid = (left + right)/2;
    if(x==a[mid]) return a[mid];
    if(x>a[mid]) left = mid+1;
    else if(x<a[mid]) right = mid;
  }
  return 0;
}
int main(){
  int n,k;
  cin >> n >> k;
  int p,q;
  int A[14][10]
  int bit[14][10]={};
  for(int i=0; i<k; i++) cin >> p >> q;
  rep(i,14) rep(j,10) A[i][j]=1;
  A[p][q]=0;

  for(int i=0;i<14;i++){
    bit[i][0]=A[i][0]+A[i][1]+A[i][2]+A[i][4]+A[i][5]+A[i][6];
    bit[i][1]=A[i][2]+A[i][5];
    bit[i][2]=A[i][0]+A[i][2]+A[i][3]+A[i][4]+A[i][6];
    bit[i][3]=A[i][0]+A[i][2]+A[i][3]+A[i][5]+A[i][6];
    bit[i][4]=A[i][1]+A[i][2]+A[i][3]+A[i][5];
    bit[i][5]=A[i][0]+A[i][1]+A[i][3]+A[i][5]+A[i][6];
    bit[i][6]=A[i][0]+A[i][1]+A[i][3]+A[i][4]+A[i][5]+A[i][6];
    bit[i][7]=A[i][0]+A[i][2]+A[i][5];
    bit[i][8]=A[i][0]+A[i][1]+A[i][2]+A[i][3]+A[i][4]+A[i][5]+A[i][6];
    bit[i][9]=A[i][0]+A[i][1]+A[i][2]+A[i][3]+A[i][5]+A[i][6];
  }

  for(int i=1; i<=24; i++){
    for(int j=1; j<=59; j++){
      for(int k=1; k<=59; k++){
          int sum=0;
          sum+=bit[8][i/10];
          sum+=bit[9][i%10];
          sum+=bit[10][j/10];
          sum+=bit[11][j%10];
          sum+=bit[12][k/10];
          sum+=bit[13][k%10];
          a.push_back(sum);
        }
      }
  }
  int y,m,d,count=0,last;
  for(y=1; y<=9999; y++){
    int sum = 0;
    sum+=bit[0][y/1000];
    sum+=bit[1][y/100%10];
    sum+=bit[2][y/10%10];
    sum+=bit[3][y%10];

    for(m=1; m<=12; m++){
      if(m==4 || m==6 || m==9 || m==11) last = 30;
      if(m==2) last = check(y);
      else last = 31;
      sum+=bit[4][m/10];
      sum+=bit[5][m%10];

      for(d=1; d<=last; d++){
        sum+=bit[6][d/10];
        sum+=bit[7][d%10];
        if(sum+search(sum,n)==n) count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}
*/



Measured memory_bytes: 3096