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