#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int INF = 2147483647;
const long long int LINF = 9223372036854775807;
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long int> a(n, -1);
  int s, c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (a[s - 1] == -1 || a[s - 1] == c) {
      a[s - 1] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (a[0] == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < n; i++) {
      if (a[i] == -1)
        cout << 0;
      else
        cout << a[i];
    }
  }
  return 0;
}
