#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<endl
#define f first
#define s second
#define endl '\n'
#define sq(x) (x)*(x)*1ll
typedef long long ll;
typedef pair<int,int> pii;

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do something instead of nothing and stay organized
*/

int mas[3]{-1,-1,-1};
int main () {
      int n ,m;
      cin>>n>>m;
      while (m--) {
            int a,b;
            cin>>a>>b; a--;
            if (mas[a] != -1 && mas[a] != b) {
                  goto NO;
            }
            mas[a]=b;
      }

      int start = pow(10,n-1);
      if (start == 1) start--;
      for (int i=start; i<pow(10,n); i++) {
            string cur = to_string(i);
            bool ok=true;
            for (int j = 0; j<cur.size(); j++) {
                  if (mas[j] == -1) continue;
                  if (mas[j] != cur[j] - '0') ok=false;
            }

            if (ok) {
                  cout << i << endl;
                  return 0;
            }
      }

      NO: cout << -1 << endl;
      return 0;
}