#include <bits/stdc++.h>
constexpr auto mod = 1000000007;
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> a(n);
  for (int i = 0; i < (int)(n); i++) {
    a[i] = -1;
  }
  int flag = 0;
  for (int i = 0; i < (int)(n); i++) {
    if (n == 1 && s[i] == 1 && c[i] == 0) {
      flag = -1;
      break;
    }
  }
  for (int i = 0; i < (int)(n); i++) {
    if (a[s[i]] == -1) {
      a[s[i]] = c[i];
    } else {
      if (a[s[i]] != c[i]) {
        flag = -1;
        break;
      }
    }
  }
  if (flag == -1) {
    cout << -1;
  } else {
    if (n != 1) {
      for (int i = 0; i < n; i++) {
        if (a[i] == -1) {
          if (i == 0) {
            cout << 1;
          } else {
            cout << 0;
          }
        } else {
          cout << a[i];
        }
      }
    } else {
      if (a[0] == -1) {
        cout << 0;
      } else {
        cout << a[0];
      }
    }
  }
}
