#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, cnt = 0;
  cin >> n;
  cin >> m;
  int ans[n];
  for (int i = 0; i < n; i++) {
    ans[n] = 0;
  }
  if (m == 0) {
    if (n == 1) {
      cout << 0 << flush;
      return 0;
    } else {
      cout << 1 << flush;
    }
    for (int i = 0; i < n - 1; i++) {
      cout << 0 << flush;
    }
    return 0;
  }
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  for (int i = 0; i < m; i++) {
    if (s[i] == 1) {
      if (c[i] == 0) {
        if (n > 1) {
          cout << -1 << flush;
          return 0;
        }
      }
    }
  }
  for (int i = 0; i < m - 1; i++) {
    for (int j = i + 1; j < m; j++) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          cout << -1 << flush;
          return 0;
        }
      }
    }
  }
  for (int i = 0; i < m; i++) {
    ans[s[i] - 1] = c[i];
    if (s[i] == 1) {
      if (c[i] == 0) {
        cout << -1 << flush;
        return 0;
      }
      cnt = 1;
    }
  }
  if (cnt == 0) {
    ans[0] = 1;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << flush;
  }
}
