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