#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  vector<pair<int, int>> num;
  cin >> n >> m;
  int ans[n + 1];
  for (int i = 0; i < n + 2; i++) {
    ans[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    num.push_back(make_pair(s, c));
  }
  for (int i = 0; i < m; i++) {
    int s = num[i].first;
    int c = num[i].second;
    if (ans[s] != -1) {
      if (ans[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
    ans[s] = c;
  }
  if (n == 1) {
    if (ans[1] == -1)
      cout << 0 << endl;
    else
      cout << ans[1] << endl;
  } else {
    if (ans[1] == -1) {
      cout << 1;
      for (int i = 2; i < m + 1; i++) {
        if (ans[i] == -1)
          cout << 0;
        else
          cout << ans[i];
      }
      cout << endl;
    } else if (ans[1] == 0) {
      cout << -1 << endl;
    } else {
      cout << ans[1];
      for (int i = 2; i < m + 1; i++) {
        if (ans[i] == -1)
          cout << 0;
        else
          cout << ans[i];
      }
      cout << endl;
    }
  }
  return 0;
}
