#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    vector<int> a(n + 1), vis(n + 1);
    int x, y;
    bool flag = true;
    for (int i = 1; i <= m; i++) {
      cin >> x >> y;
      if (x == 1) {
        if (y == 0)
          continue;
        else if (a[x] == 0)
          a[x] = y;
        else
          a[x] = min(a[x], y);
      } else if (vis[x] == true)
        a[x] = min(a[x], y);
      else
        a[x] = y, vis[i] = true;
    }
    if (n != 1 and a[1] == 0) flag = false;
    if (flag)
      for (int i = 1; i <= n; i++) cout << a[i];
    else
      cout << -1;
    cout << endl;
  }
  return 0;
}
