#include <bits/stdc++.h>
using namespace std;
const long long int mxsize = 3e5 + 5;
const long long int linf = 1e9;
const long double inf = 10000000000.0;
const long long int mod = 1e9 + 9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int N, M;
  cin >> N >> M;
  map<int, int> mp;
  while (M--) {
    int s, c;
    cin >> s >> c;
    if (mp.find(s) == mp.end()) {
      mp[s] = c;
    } else {
      if (mp[s] != c) {
        cout << -1 << endl;
        return 0;
      } else {
        mp[s] = c;
      }
    }
  }
  if (mp.size() == 1) {
    for (auto x : mp) {
      if (x.second == 0 && N == 1) {
        cout << 0 << endl;
        return 0;
      } else if (x.second == 0 && x.first == 1 && N > 1) {
        cout << -1 << endl;
        return 0;
      }
    }
  } else {
    vector<int> ans(N + 1);
    for (auto x : mp) {
      if (x.first <= N) {
        ans[x.first] = x.second;
      }
    }
    if (N == 1 && ans[1] == 0) {
      cout << 0 << endl;
      return 0;
    } else if (N > 1 && ans[1] == 0) {
      ans[1] = 1;
    }
    for (int i = 1; i <= N; i++) {
      cout << ans[i];
    }
    return 0;
  }
}
