#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = 1e18;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int D[n + 1];
  for (int i = 1; i <= n; i++) {
    D[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    int second, c;
    cin >> second >> c;
    if (D[second] == -1)
      D[second] = c;
    else {
      if (D[second] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (D[i] == -1) D[i] = 0;
    if (D[i] == 0) cnt++;
  }
  if (cnt == n) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (D[i] == 0)
      continue;
    else {
      for (int j = i; j <= n; j++) {
        cout << D[j];
      }
      return 0;
    }
  }
  return 0;
}
