#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0, flag = 0;
  vector<int> a(n + 1, 10), visited(n + 1, false);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (a[s] == c || visited[s] == false) {
      visited[s] = true;
      a[s] = c;
      flag = true;
    } else {
      flag = false;
      break;
    }
  }
  if (!flag)
    cout << -1;
  else {
    if (n == 1) {
      if (a[1] == 10) ans = 0;
    } else {
      for (int i = 1; i < 4; i++) {
        if ((a[1] == 0)) {
          ans = -1;
          break;
        }
        if (a[i] == 10 && i == 1)
          a[i] = 1;
        else if (a[i] == 10)
          a[i] = 0;
        ans += a[i] * pow(10, n - i);
      }
    }
    cout << ans;
  }
}
