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