#include <bits/stdc++.h>
using namespace std;
int s[10];
int main(void) {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    if (n == 1) cout << 0 << endl;
    if (n == 2) cout << 10 << endl;
    if (n == 3) cout << 100 << endl;
    return 0;
  }
  for (int i = 0; i < 10; i++) s[i] = -1;
  bool flag = false;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (x != 1) {
      if (s[x] != -1) {
        if (s[x] != y) flag = true;
      } else
        s[x] = y;
    } else {
      if (s[x] != -1) {
        if (s[x] != y) flag = true;
      } else {
        if (y == 0)
          flag = true;
        else
          s[x] = y;
      }
    }
  }
  if (flag) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i == 1) {
      if (s[i] == -1)
        ans += (int)pow(10, n - 1);
      else
        ans += (int)pow(10, n - 1) * s[i];
    } else {
      if (s[i] == -1)
        ans += 0;
      else
        ans += (int)pow(10, n - i) * s[i];
    }
  }
  cout << ans << endl;
  return 0;
}
