#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int mod = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  int c[n + 1];
  for (int i = 0; i < n + 1; i++) {
    c[i] = -1;
  }
  bool flag = false;
  for (int i = 0; i < m; i++) {
    int s, x;
    cin >> s >> x;
    if (c[s] == -1) {
      c[s] = x;
    } else if (c[s] != x) {
      flag = true;
    }
  }
  if (flag) {
    cout << "-1";
    return 0;
  }
  if (c[1] == 0 && n > 1) {
    cout << "-1";
    return 0;
  } else if (c[1] == -1) {
    c[1] = 1;
  }
  for (int i = 1; i < n + 1; i++) {
    if (c[i] == -1) {
      c[i] = 0;
    }
    cout << c[i];
  }
}
