#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N, M;
  cin >> N >> M;
  vector<int> d(N, -1);
  bool err = false;
  for (int i = 0; i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (d[s] == -1) {
      d[s] = c;
    } else if (d[s] != c) {
      err = true;
    }
  }
  int ans = -1;
  if (!err) {
    ans = 0;
    for (int i = 0; i < (N); ++i) {
      if (d[i] == -1) {
        if (i == 0) {
          if (N == 1) {
            d[0] = 0;
          } else {
            d[0] = 1;
          }
        } else {
          d[i] = 0;
        }
      }
      ans = ans * 10 + d[i];
    }
  }
  cout << ans << endl;
  return 0;
}
