#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9;
const ll INF = 4e18;
const ll dy[4] = {1, 0, -1, 0};
const ll dx[4] = {0, -1, 0, 1};
long long fac(ll a) {
  long long ans = 1;
  while (a > 1) {
    ans *= a;
    ans %= 1000000007;
    a--;
  }
  return ans;
}
int main() {
  ll N;
  ll M;
  cin >> N >> M;
  vector<pl> vec(M);
  for (ll i = 0; i < M; i++) {
    cin >> vec.at(i).first >> vec.at(i).second;
  }
  sort((vec).begin(), (vec).end());
  if (M != 1) {
    ll a = 0;
    for (ll i = 0; i < M - 1; i++) {
      if ((vec.at(i).first == vec.at(i + 1).first) &&
          (vec.at(i).second != vec.at(i + 1).second)) {
        a++;
      }
      if (a != 0) {
        cout << -1;
        return 0;
      } else if (a == 0) {
        ll maxi = vec.at(M - 1).first;
        ll mini = vec.at(0).first;
        ll maxim = vec.at(M - 1).second;
        ll minim = vec.at(0).second;
        if (maxi > N) {
          cout << -1;
          return 0;
        } else if (maxi == N) {
          if (minim == 0) {
            cout << -1;
            return 0;
          } else if (minim != 0) {
            for (ll i = (1); i < (N + 1); i++) {
              ll c = 19;
              for (ll j = 0; j < M; j++) {
                if (vec.at(j).first == i) {
                  c = vec.at(j).second;
                  break;
                }
              }
              if ((c == 19) && (i == 1)) {
                cout << 1;
              }
              if ((c == 19) && (i != 1)) {
                cout << 0;
              }
              if (c != 19) {
                cout << c;
              }
            }
          }
          return 0;
        } else if (maxi < N) {
          if (minim == 0) {
            cout << -1;
            return 0;
          } else if (minim != 0) {
            if (mini == 1) {
              cout << vec.at(0).second;
              for (ll i = (2); i < (N + 1); i++) {
                ll c = 19;
                for (ll g = 0; g < M; g++) {
                  if (vec.at(g).first == i) {
                    c = vec.at(g).second;
                    break;
                  }
                }
                if (c == 19) {
                  cout << 0;
                } else if (c != 19) {
                  cout << c;
                }
              }
              return 0;
            } else if (mini != 1) {
              cout << 1;
              for (ll i = (1); i < (mini - 1); i++) {
                cout << 0;
              }
              for (ll i = (mini); i < (N + 1); i++) {
                ll c = 19;
                for (ll g = 0; g < M; g++) {
                  if (vec.at(g).first == i) {
                    c = vec.at(g).second;
                    break;
                  }
                }
                if (c == 19) {
                  cout << 0;
                } else if (c != 19) {
                  cout << c;
                }
              }
              return 0;
            }
          }
        }
      }
    }
  } else if (M == 1) {
    if (vec.at(0).second == 0) {
      cout << -1;
      return 0;
    } else if (vec.at(0).second != 0) {
      cout << vec.at(0).second;
      if (N > 1) {
        for (ll i = 0; i < N - 1; i++) {
          cout << 0;
        }
      }
    }
  }
  cout << endl;
}
