#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  bool f = false;
  REP(i, m){
    int a , b;
    cin >> a >> b;
    a--;
    if(mp[a] == 0) mp[a] = b;
    if(mp[a] != b) f = true;
  }
  if(f){
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  REP(i, n){
    ans += mp[i] * pow(10, n-i-1);
  }
  string s = to_string(ans);
  if(s.size() != n){
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}