#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  int n, m;
  cin >> n >> m;
  int s, c, ans[n];
  fill(ans, ans + n, INF);
  bool flag = true;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (ans[s - 1] == INF || ans[s - 1] == c)
      ans[s - 1] = c;
    else
      flag = false;
  }
  if (ans[0] == 0) flag = false;
  if (flag) {
    for (int i = 0; i < n; i++) {
      if (ans[i] == INF) {
        if (i > 0)
          cout << 0;
        else
          cout << 1;
      } else
        cout << ans[i];
    }
    cout << endl;
  } else
    cout << -1 << endl;
}
