Language: C++

#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}
long comb(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
using namespace std;
/*int main(){
    int n;std::cin >> n;
    int keta=0;
    while(true){
        keta++;
        if(n/10==0)break;
        n=n/10;
    }
    keta=keta-1;
    if(n>=7)n=3;
    else if(n>=5)n=2;
    else if(n>=3)n=1;
    int k=0;
    for(int i=3;i<=keta;i++){
        k+=comb(i-1,2);
        std::cout << k << std::endl;
    }std::cout << k << std::endl;
    k+=n*(keta);
    
    std::cout << k << std::endl;
    
}


*/
int main(){
  int n,m;
  
  std::cin >> n>>m;
  int a[n+1];
  rep(i,n+1)a[i]=0;
  int s[m],c[m];
  rep(i,m)std::cin >> s[i]>>c[i];
  if(n==1){
      int k=c[0];
      rep(i,m){
          if(k!=c[i]){
              std::cout << -1 << std::endl;
              return 0;
          }
      }
      std::cout << k << std::endl;
      return 0;
  }
  else{
  rep(i,m){
      if(s[i]==1){
          if(c[i]==0){
              std::cout << -1 << std::endl;
              return 0;
          }
          else if(a[1]==0)a[1]=c[i];
          else if(a[1]!=c[i]){
              std::cout << -1 << std::endl;
              return 0;
          }
      }
      else if(a[s[i]]==0)a[s[i]]=c[i];
      else if(a[s[i]]!=c[i]){
              std::cout << -1 << std::endl;
              return 0;
          }
  }
  if(a[1]==0)a[1]=1;
  int ans=0;
  rep(i,n+1){
      ans+=a[i]*pow(10,n-i);
  }
  std::cout << ans << std::endl;
  #include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}
long comb(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
using namespace std;
/*int main(){
    int n;std::cin >> n;
    int keta=0;
    while(true){
        keta++;
        if(n/10==0)break;
        n=n/10;
    }
    keta=keta-1;
    if(n>=7)n=3;
    else if(n>=5)n=2;
    else if(n>=3)n=1;
    int k=0;
    for(int i=3;i<=keta;i++){
        k+=comb(i-1,2);
        std::cout << k << std::endl;
    }std::cout << k << std::endl;
    k+=n*(keta);
    
    std::cout << k << std::endl;
    
}


*/
int main(){
  int n,m;
  
  std::cin >> n>>m;
  int a[n+1];
  rep(i,n+1)a[i]=0;
  int s[m],c[m];
  rep(i,m)std::cin >> s[i]>>c[i];
  if(n==1){
      int k=c[1];
      rep(i,m){
          if(k!=c[i]){
              std::cout << -1 << std::endl;
              return 0;
          }
      }
      std::cout << k << std::endl;
      return 0;
  }
  rep(i,m){
      if(s[i]==1){
          if(c[i]==0){
              std::cout << -1 << std::endl;
              return 0;
          }
          else if(a[1]==0)a[1]=c[i];
          else if(a[1]!=c[i]){
              std::cout << -1 << std::endl;
              return 0;
          }
      }
      else if(a[s[i]]==0)a[s[i]]=c[i];
      else if(a[s[i]]!=c[i]){
              std::cout << -1 << std::endl;
              return 0;
          }
  }
  if(a[1]==0)a[1]=1;
  int ans=0;
  rep(i,n+1){
      ans+=a[i]*pow(10,n-i);
  }
  std::cout << ans << std::endl;
}





}






Compiler output:
a.cc: In function 'int main()':
a.cc:122:21: error: a function-definition is not allowed here before '{' token
  122 | int binary(int bina){
      |                     ^
a.cc:131:25: error: a function-definition is not allowed here before '{' token
  131 | long comb(int n, int r) {
      |                         ^
a.cc:167:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  167 | int main(){
      |         ^~
a.cc:167:9: note: remove parentheses to default-initialize a variable
  167 | int main(){
      |         ^~
      |         --
a.cc:167:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:167:11: error: a function-definition is not allowed here before '{' token
  167 | int main(){
      |           ^
a.cc:216:2: error: expected '}' at end of input
  216 | }
      |  ^
a.cc:62:11: note: to match this '{'
   62 | int main(){
      |           ^