#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> sc(m);
  for (int i = 0; i < m; i++) cin >> sc[i].first >> sc[i].second;
  vector<int> ans(n);
  for (int i = 1; i < n; i++) ans[i] = 0;
  sort(sc.begin(), sc.end());
  if (n == 1) {
    ans[0] = sc[0].second;
    for (int i = 1; i < m; i++) {
      if (ans[0] != sc[i].second) {
        ans[0] = -1;
        break;
      }
    }
    cout << ans[0] << endl;
  } else {
    ans[0] = 1;
    int i = 1;
    int x = sc[0].first;
    ans[x - 1] = sc[0].second;
    if (ans[0] == 0)
      cout << -1 << endl;
    else if (m == 1) {
      for (int i = 0; i < n; i++) cout << ans[i] << endl;
    } else {
      while (i < m) {
        if (x == sc[i].first) {
          if (sc[x].second != sc[i].second) {
            cout << -1 << endl;
            break;
          } else if (i == m - 1) {
            for (int i = 0; i < n; i++) cout << ans[i];
          }
        } else {
          x = sc[i].first;
          ans[x - 1] = sc[i].second;
          if (i == m - 1) {
            for (int i = 0; i < n; i++) cout << ans[i];
          }
        }
        i++;
      }
    }
  }
}
